01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.openjpa.lib.conf;
20:
21: import java.util.List;
22:
23: import junit.framework.TestCase;
24: import org.apache.openjpa.lib.util.Options;
25:
26: public class TestAnchorParsing extends TestCase {
27:
28: public void testFQAnchor() {
29: String fqLoc = "META-INF/persistence.xml#test";
30: Options opts = new Options();
31: opts.setProperty("p", fqLoc);
32: List locs = Configurations
33: .getFullyQualifiedAnchorsInPropertiesLocation(opts);
34: assertNotNull(locs);
35: assertEquals(1, locs.size());
36: assertEquals(fqLoc, locs.get(0));
37: }
38:
39: public void testNoResource() {
40: allHelper(null);
41: }
42:
43: public void testNoAnchor() {
44: allHelper("META-INF/persistence.xml");
45: }
46:
47: private void allHelper(String resource) {
48: Options opts = new Options();
49: if (resource != null)
50: opts.setProperty("p", resource);
51: List locs = Configurations
52: .getFullyQualifiedAnchorsInPropertiesLocation(opts);
53: assertNotNull(locs);
54: // approximate so that if someone adds more units, this doesn't break
55: assertTrue(locs.size() >= 4);
56: assertTrue(locs.contains("META-INF/persistence.xml#test"));
57: assertTrue(locs
58: .contains("META-INF/persistence.xml#second-persistence-unit"));
59: assertTrue(locs
60: .contains("META-INF/persistence.xml#third-persistence-unit"));
61: assertTrue(locs.contains("META-INF/persistence.xml#invalid"));
62: }
63: }
|