View Javadoc

1   package org.apache.archiva.redback.components.modello.jpox;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.codehaus.modello.ModelloParameterConstants;
23  import org.codehaus.modello.core.ModelloCore;
24  import org.codehaus.modello.model.Model;
25  import org.codehaus.plexus.util.ReaderFactory;
26  import org.dom4j.Document;
27  import org.dom4j.io.SAXReader;
28  
29  import java.io.File;
30  import java.util.Properties;
31  
32  /**
33   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
34   * @version $Id: JPoxJdoMappingModelloGeneratorPrefixedTest.java 1414999 2012-11-28 23:55:28Z olamy $
35   */
36  public class JPoxJdoMappingModelloGeneratorPrefixedTest extends AbstractJpoxGeneratorTestCase
37  {
38      public JPoxJdoMappingModelloGeneratorPrefixedTest()
39      {
40          super( "jpox-jdo-mapping" );
41      }
42  
43      public void testInvocationWithPrefixes() throws Exception
44      {
45          ModelloCore core = (ModelloCore) lookup( ModelloCore.ROLE );
46  
47          Model model = core.loadModel( ReaderFactory.newXmlReader( getTestFile( "src/test/resources/test-with-prefixes.mdo" ) ) );
48  
49          // ----------------------------------------------------------------------
50          // Generate the code
51          // ----------------------------------------------------------------------
52  
53          Properties parameters = new Properties();
54  
55          parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() );
56  
57          parameters.setProperty( ModelloParameterConstants.VERSION, "1.0.0" );
58  
59          parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.FALSE.toString() );
60  
61          core.generate( model, "jpox-jdo-mapping", parameters );
62  
63          // ----------------------------------------------------------------------
64          // Assert
65          // ----------------------------------------------------------------------
66  
67          assertGeneratedFileExists( "package.jdo" );
68  
69          SAXReader reader = new SAXReader();
70          reader.setEntityResolver( new JdoEntityResolver() );
71          Document jdoDocument = reader.read( new File( getOutputDirectory() + "/package.jdo" ) );
72  
73          assertNotNull( jdoDocument );
74  
75          // Tree should consist of only elements with attributes. NO TEXT.
76          assertNoTextNodes( jdoDocument, "//jdo", true );
77  
78          assertAttributeEquals( jdoDocument,
79                                 "//class[@name='RbacJdoModelModelloMetadata']/field[@name='modelVersion']/column",
80                                 "default-value", "1.0.0" );
81  
82          assertAttributeEquals( jdoDocument, "//class[@name='JdoResource']/field[@name='modelEncoding']", "persistence-modifier",
83                                 "none" );
84  
85          // -----------------------------------------------------------------------
86          // Association Tests.
87  
88          //   mdo/association/jpox.dependent-element == false (only on association with "*" multiplicity (default type)
89          assertAttributeEquals( jdoDocument, "//class[@name='JdoRole']/field[@name='permissions']/collection",
90                                 "dependent-element", "false" );
91  
92          //   mdo/association (default type) with "1" multiplicity.
93          assertElementNotExists( jdoDocument, "//class[@name='JdoPermission']/field[@name='operation']/collection" );
94  
95          // -----------------------------------------------------------------------
96          // Fetch Group Tests
97          assertAttributeMissing( jdoDocument, "//class[@name='JdoRole']/field[@name='assignable']", "default-fetch-group" );
98          assertAttributeEquals( jdoDocument, "//class[@name='JdoRole']/field[@name='childRoleNames']",
99                                 "default-fetch-group", "true" );
100 
101         // -----------------------------------------------------------------------
102         // Alternate Table and Column Names Tests.
103         assertAttributeEquals( jdoDocument, "//class[@name='JdoPermission']", "table", "SECURITY_PERMISSIONS" );
104         assertAttributeEquals( jdoDocument, "//class[@name='JdoOperation']/field[@name='name']/column", "name", "OPERATION_NAME" );
105         assertAttributeEquals( jdoDocument, "//class[@name='JdoRole']/field[@name='permissions']", "table", "SECURITY_ROLE_PERMISSION_MAP" );
106     }
107 }