Changeset 6920 for ComponentRegistry


Ignore:
Timestamp:
01/21/16 08:02:54 (8 years ago)
Author:
Twan Goosen
Message:

merged fix from 2.0 branch

Location:
ComponentRegistry/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk

  • ComponentRegistry/trunk/ComponentRegistry

  • ComponentRegistry/trunk/ComponentRegistry/src/test/java

  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/MDValidatorTest.java

    r5549 r6920  
    1717
    1818import org.junit.Before;
    19 import org.junit.Ignore;
    2019import org.junit.Test;
    2120import org.springframework.beans.factory.annotation.Autowired;
    2221
    23 
    2422/**
    25  * 
     23 *
    2624 * @author george.georgovassilis@mpi.nl
    2725 *
     
    3028
    3129    @Autowired
    32     private ComponentRegistryFactory componentRegistryFactory; 
     30    private ComponentRegistryFactory componentRegistryFactory;
    3331    @Autowired
    3432    private ComponentRegistry testRegistry;
    35    
     33
    3634    private RegistryUser user;
    37    
    38    
     35
    3936    @Before
    4037    @Override
     
    4340        user = componentRegistryFactory.getOrCreateUser(DummyPrincipal.DUMMY_CREDENTIALS);
    4441    }
    45    
    46    
    47 
    48     @Test
    49     public void testValidateSucces() throws UserUnauthorizedException{
    50         MDValidator validator = this.getValidProfileValidator();
     42
     43    @Test
     44    public void testValidateSucces() throws UserUnauthorizedException {
     45        MDValidator validator = this.getValidProfileValidator();
    5146        boolean result = validator.validate();
    52         assertTrue(result);
    53     }
    54 
    55     @Test
    56     public void testValidateIllegalComponentAttributeName() throws UserUnauthorizedException{
    57         String profileContent = "";
    58         profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    59         profileContent += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    60         profileContent += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    61         profileContent += "    <Header />\n";
    62         profileContent += "    <CMD_Component name=\"Actor\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n";
    63         profileContent += "        <AttributeList>\n";
    64         profileContent += "             <Attribute>\n";
    65         profileContent += "                 <Name>myattribute</Name>\n"; // this should be
    66                                                               // allowed
    67         profileContent += "                 <Type>string</Type>\n";
    68         profileContent += "             </Attribute>\n";
    69         profileContent += "             <Attribute>\n";
    70         profileContent += "                 <Name>ref</Name>\n"; // this should NOT be
    71                                                       // allowed
    72         profileContent += "                 <Type>string</Type>\n";
    73         profileContent += "             </Attribute>\n";
    74         profileContent += "             <Attribute>\n";
    75         profileContent += "                 <Name>ComponentId</Name>\n"; // neither should
    76                                                               // this
    77         profileContent += "                 <Type>string</Type>\n";
    78         profileContent += "             </Attribute>\n";
    79         profileContent += "        </AttributeList>\n";
    80         profileContent += "        <CMD_Element name=\"Age\">\n";
    81         profileContent += "             <AttributeList>\n";
    82         profileContent += "                 <Attribute>\n";
    83         profileContent += "                     <Name>ref</Name>\n"; // allowed here, only
    84                                                    // forbidden on components
    85         profileContent += "                     <Type>string</Type>\n";
    86         profileContent += "                 </Attribute>\n";
    87         profileContent += "                 <Attribute>\n";
    88         profileContent += "                     <Name>ComponentId</Name>\n"; // allowed here, only
    89                                                            // forbidden on
    90                                                            // components
    91         profileContent += "                     <Type>string</Type>\n";
    92         profileContent += "                 </Attribute>\n";
    93         profileContent += "             </AttributeList>\n";
    94         profileContent += "            <ValueScheme>\n";
    95         profileContent += "                <pattern>[23][0-9]</pattern>\n";
    96         profileContent += "            </ValueScheme>\n";
    97         profileContent += "        </CMD_Element>\n";
    98         profileContent += "    </CMD_Component>\n";
    99         profileContent += "</CMD_ComponentSpec>\n";
    100         InputStream input = new ByteArrayInputStream(profileContent.getBytes());
    101 
    102         ProfileDescription desc = ProfileDescription.createNewDescription();
    103        
    104         MDValidator validator = new MDValidator(input, desc, testRegistry, marshaller);
    105         assertFalse(validator.validate());
    106         assertEquals(4, validator.getErrorMessages().size());
    107         assertTrue(validator.getErrorMessages().get(0)
    108                 .startsWith(MDValidator.PARSE_ERROR));
    109         assertTrue(validator.getErrorMessages().get(1)
    110                 .startsWith(MDValidator.PARSE_ERROR));
     47        assertTrue(result);
     48    }
     49
     50    @Test
     51    public void testValidateIllegalComponentAttributeName() throws UserUnauthorizedException {
     52        String profileContent = "";
     53        profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     54        profileContent += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     55        profileContent += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     56        profileContent += "    <Header />\n";
     57        profileContent += "    <CMD_Component name=\"Actor\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n";
     58        profileContent += "        <AttributeList>\n";
     59        profileContent += "             <Attribute>\n";
     60        profileContent += "                 <Name>myattribute</Name>\n"; // this should be
     61        // allowed
     62        profileContent += "                 <Type>string</Type>\n";
     63        profileContent += "             </Attribute>\n";
     64        profileContent += "             <Attribute>\n";
     65        profileContent += "                 <Name>ref</Name>\n"; // this should NOT be
     66        // allowed
     67        profileContent += "                 <Type>string</Type>\n";
     68        profileContent += "             </Attribute>\n";
     69        profileContent += "             <Attribute>\n";
     70        profileContent += "                 <Name>ComponentId</Name>\n"; // neither should
     71        // this
     72        profileContent += "                 <Type>string</Type>\n";
     73        profileContent += "             </Attribute>\n";
     74        profileContent += "        </AttributeList>\n";
     75        profileContent += "        <CMD_Element name=\"Age\">\n";
     76        profileContent += "             <AttributeList>\n";
     77        profileContent += "                 <Attribute>\n";
     78        profileContent += "                     <Name>ref</Name>\n"; // allowed here, only
     79        // forbidden on components
     80        profileContent += "                     <Type>string</Type>\n";
     81        profileContent += "                 </Attribute>\n";
     82        profileContent += "                 <Attribute>\n";
     83        profileContent += "                     <Name>ComponentId</Name>\n"; // allowed here, only
     84        // forbidden on
     85        // components
     86        profileContent += "                     <Type>string</Type>\n";
     87        profileContent += "                 </Attribute>\n";
     88        profileContent += "             </AttributeList>\n";
     89        profileContent += "            <ValueScheme>\n";
     90        profileContent += "                <pattern>[23][0-9]</pattern>\n";
     91        profileContent += "            </ValueScheme>\n";
     92        profileContent += "        </CMD_Element>\n";
     93        profileContent += "    </CMD_Component>\n";
     94        profileContent += "</CMD_ComponentSpec>\n";
     95        InputStream input = new ByteArrayInputStream(profileContent.getBytes());
     96
     97        ProfileDescription desc = ProfileDescription.createNewDescription();
     98
     99        MDValidator validator = new MDValidator(input, desc, testRegistry, marshaller);
     100        assertFalse(validator.validate());
     101        assertEquals("Messages expected for 2 failed tests:\n"
     102                + "- Actor/@ref ('ref' attribute not allowed on component)\n"
     103                + "- Actor/@ComponentId ('ComponentId' attribute not allowed on component)",
     104                2, validator.getErrorMessages().size());
     105        assertTrue(validator.getErrorMessages().get(0)
     106                .startsWith(MDValidator.PARSE_ERROR));
     107        assertTrue(validator.getErrorMessages().get(1)
     108                .startsWith(MDValidator.PARSE_ERROR));
    111109    }
    112110
    113111    @Test
    114112    public void testValidateNoComponentId() throws Exception {
    115         String profileContent = "";
    116         profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    117         profileContent += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    118         profileContent += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    119         profileContent += "    <Header />\n";
    120         profileContent += "    <CMD_Component filename=\"component-actor.xml\"/>\n";
    121         profileContent += "</CMD_ComponentSpec>\n";
    122         InputStream input = new ByteArrayInputStream(profileContent.getBytes());
    123 
    124         ProfileDescription desc = ProfileDescription.createNewDescription();
     113        String profileContent = "";
     114        profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     115        profileContent += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     116        profileContent += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     117        profileContent += "    <Header />\n";
     118        profileContent += "    <CMD_Component filename=\"component-actor.xml\"/>\n";
     119        profileContent += "</CMD_ComponentSpec>\n";
     120        InputStream input = new ByteArrayInputStream(profileContent.getBytes());
     121
     122        ProfileDescription desc = ProfileDescription.createNewDescription();
    125123        desc.setPublic(true);
    126         MDValidator validator = new MDValidator(input, desc, testRegistry, marshaller);
    127         assertFalse(validator.validate());
    128         assertTrue(validator
    129                 .getErrorMessages()
    130                 .get(0)
    131                 .startsWith(MDValidator.COMPONENT_NOT_REGISTERED_ERROR));
     124        MDValidator validator = new MDValidator(input, desc, testRegistry, marshaller);
     125        assertFalse(validator.validate());
     126        assertTrue(validator
     127                .getErrorMessages()
     128                .get(0)
     129                .startsWith(MDValidator.COMPONENT_NOT_REGISTERED_ERROR));
    132130        //
    133131    }
    134132
    135     @Test 
     133    @Test
    136134    public void testValidateComponentIdNotRegistered() throws Exception {
    137         String id1 = "component1";
    138         String id2 = "component2";
    139 
    140         String profileContent = "";
    141         profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    142         profileContent += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    143         profileContent += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">";
    144         profileContent += "    <Header />";
    145         profileContent += "    <CMD_Component name=\"Test\">";
    146         profileContent += "     <CMD_Component ComponentId=\""
    147                 + ComponentDescription.COMPONENT_PREFIX + id1 + "\"/>"; // id not
    148                                                                 // registered
    149         profileContent += "     <CMD_Component ComponentId=\""
    150                 + ComponentDescription.COMPONENT_PREFIX + id2 + "\"/>"; // id not
    151                                                                 // registered
    152         profileContent += "    </CMD_Component>";
    153         profileContent += "</CMD_ComponentSpec>";
    154 
    155         // Ids not registered. will return 2 errors: one per each id.
    156         ProfileDescription desc = ProfileDescription.createNewDescription();
     135        String id1 = "component1";
     136        String id2 = "component2";
     137
     138        String profileContent = "";
     139        profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
     140        profileContent += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     141        profileContent += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">";
     142        profileContent += "    <Header />";
     143        profileContent += "    <CMD_Component name=\"Test\">";
     144        profileContent += "     <CMD_Component ComponentId=\""
     145                + ComponentDescription.COMPONENT_PREFIX + id1 + "\"/>"; // id not
     146        // registered
     147        profileContent += "     <CMD_Component ComponentId=\""
     148                + ComponentDescription.COMPONENT_PREFIX + id2 + "\"/>"; // id not
     149        // registered
     150        profileContent += "    </CMD_Component>";
     151        profileContent += "</CMD_ComponentSpec>";
     152
     153        // Ids not registered. will return 2 errors: one per each id.
     154        ProfileDescription desc = ProfileDescription.createNewDescription();
    157155        desc.setPublic(true);
    158         MDValidator validator = new MDValidator(new ByteArrayInputStream(
    159                 profileContent.getBytes()), desc, testRegistry, marshaller);
    160         assertFalse(validator.validate());
    161         assertEquals(1, validator.getErrorMessages().size());
    162         assertTrue(validator
    163                 .getErrorMessages()
    164                 .get(0)
    165                 .startsWith(MDValidator.COMPONENT_NOT_REGISTERED_ERROR));
    166        
    167 
    168         // id1 will be added as public and therefore only id2 is not registered
    169         RegistryTestHelper.addComponent(testRegistry, id1, true);
    170         validator = new MDValidator(new ByteArrayInputStream(
    171                 profileContent.getBytes()), desc, testRegistry
    172                 , marshaller);
    173         assertFalse(validator.validate());
    174         assertEquals(1, validator.getErrorMessages().size());
    175         assertTrue(validator
    176                 .getErrorMessages()
    177                 .get(0)
    178                 .startsWith(MDValidator.COMPONENT_NOT_REGISTERED_ERROR));
    179 
    180         // id2 is added as public, no more errors shoud be return
    181         RegistryTestHelper.addComponent(testRegistry, id2, true);
    182         validator = new MDValidator(new ByteArrayInputStream(
    183                 profileContent.getBytes()), desc, testRegistry, marshaller);
    184         assertTrue("component is registered should be valid now",
    185                 validator.validate());
    186         assertEquals(0, validator.getErrorMessages().size());
     156        MDValidator validator = new MDValidator(new ByteArrayInputStream(
     157                profileContent.getBytes()), desc, testRegistry, marshaller);
     158        assertFalse(validator.validate());
     159        assertEquals(1, validator.getErrorMessages().size());
     160        assertTrue(validator
     161                .getErrorMessages()
     162                .get(0)
     163                .startsWith(MDValidator.COMPONENT_NOT_REGISTERED_ERROR));
     164
     165        // id1 will be added as public and therefore only id2 is not registered
     166        RegistryTestHelper.addComponent(testRegistry, id1, true);
     167        validator = new MDValidator(new ByteArrayInputStream(
     168                profileContent.getBytes()), desc, testRegistry, marshaller);
     169        assertFalse(validator.validate());
     170        assertEquals(1, validator.getErrorMessages().size());
     171        assertTrue(validator
     172                .getErrorMessages()
     173                .get(0)
     174                .startsWith(MDValidator.COMPONENT_NOT_REGISTERED_ERROR));
     175
     176        // id2 is added as public, no more errors shoud be return
     177        RegistryTestHelper.addComponent(testRegistry, id2, true);
     178        validator = new MDValidator(new ByteArrayInputStream(
     179                profileContent.getBytes()), desc, testRegistry, marshaller);
     180        assertTrue("component is registered should be valid now",
     181                validator.validate());
     182        assertEquals(0, validator.getErrorMessages().size());
    187183    }
    188184
    189185    @Test
    190186    public void testValidateBaseAndUserRegistry() throws Exception {
    191         String id1 = "component1";
    192         String id2 = "component2";
    193 
    194         String profileContent = "";
    195         profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    196         profileContent += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"";
    197         profileContent += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">";
    198         profileContent += "    <Header />";
    199         profileContent += "    <CMD_Component name=\"Test\">";
    200         profileContent += "     <CMD_Component ComponentId=\""
    201                 + ComponentDescription.COMPONENT_PREFIX + id1 + "\"/>"; // id not
    202                                                                 // registered
    203         profileContent += "     <CMD_Component ComponentId=\""
    204                 + ComponentDescription.COMPONENT_PREFIX + id2 + "\"/>"; // id not
    205                                                                 // registered
    206         profileContent += "    </CMD_Component>";
    207         profileContent += "</CMD_ComponentSpec>";
     187        String id1 = "component1";
     188        String id2 = "component2";
     189
     190        String profileContent = "";
     191        profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
     192        profileContent += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"";
     193        profileContent += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">";
     194        profileContent += "    <Header />";
     195        profileContent += "    <CMD_Component name=\"Test\">";
     196        profileContent += "     <CMD_Component ComponentId=\""
     197                + ComponentDescription.COMPONENT_PREFIX + id1 + "\"/>"; // id not
     198        // registered
     199        profileContent += "     <CMD_Component ComponentId=\""
     200                + ComponentDescription.COMPONENT_PREFIX + id2 + "\"/>"; // id not
     201        // registered
     202        profileContent += "    </CMD_Component>";
     203        profileContent += "</CMD_ComponentSpec>";
    208204
    209205        // Public Registry
    210         ProfileDescription desc = ProfileDescription.createNewDescription();
    211         MDValidator validator = new MDValidator(new ByteArrayInputStream(
    212                 profileContent.getBytes()), desc, testRegistry, marshaller);
    213         assertFalse(validator.validate());
    214         assertEquals(1, validator.getErrorMessages().size()); // the exception is thrown and propagated on the first non-registered component
    215         assertTrue(validator.getErrorMessages().get(0)
    216                 .startsWith(MDValidator.COMPONENT_NOT_REGISTERED_ERROR));
    217        
    218        
     206        ProfileDescription desc = ProfileDescription.createNewDescription();
     207        MDValidator validator = new MDValidator(new ByteArrayInputStream(
     208                profileContent.getBytes()), desc, testRegistry, marshaller);
     209        assertFalse(validator.validate());
     210        assertEquals(1, validator.getErrorMessages().size()); // the exception is thrown and propagated on the first non-registered component
     211        assertTrue(validator.getErrorMessages().get(0)
     212                .startsWith(MDValidator.COMPONENT_NOT_REGISTERED_ERROR));
     213
    219214        // registering publically the first component
    220         RegistryTestHelper.addComponent(testRegistry, id1, true);
    221         validator = new MDValidator(new ByteArrayInputStream(
    222                 profileContent.getBytes()), desc, testRegistry, marshaller);
    223         assertFalse(validator.validate());
    224         assertEquals(1, validator.getErrorMessages().size()); // the exception is thrown on the second non-registered component
    225         assertTrue(validator.getErrorMessages().get(0)
    226                 .startsWith(MDValidator.COMPONENT_NOT_REGISTERED_ERROR));
    227        
    228        
    229        
    230         RegistryTestHelper.addComponent(testRegistry, id2, false);
    231         validator = new MDValidator(new ByteArrayInputStream(
    232                 profileContent.getBytes()), desc, testRegistry, marshaller);
    233         assertFalse(validator.validate());
    234         assertEquals(1, validator.getErrorMessages().size());
    235         assertTrue(validator
    236                 .getErrorMessages()
    237                 .get(0)
    238                 .startsWith(MDValidator.COMPONENT_NOT_REGISTERED_IN_APPROPRIATE_SPACE_ERROR));
    239        
    240        
     215        RegistryTestHelper.addComponent(testRegistry, id1, true);
     216        validator = new MDValidator(new ByteArrayInputStream(
     217                profileContent.getBytes()), desc, testRegistry, marshaller);
     218        assertFalse(validator.validate());
     219        assertEquals(1, validator.getErrorMessages().size()); // the exception is thrown on the second non-registered component
     220        assertTrue(validator.getErrorMessages().get(0)
     221                .startsWith(MDValidator.COMPONENT_NOT_REGISTERED_ERROR));
     222
     223        RegistryTestHelper.addComponent(testRegistry, id2, false);
     224        validator = new MDValidator(new ByteArrayInputStream(
     225                profileContent.getBytes()), desc, testRegistry, marshaller);
     226        assertFalse(validator.validate());
     227        assertEquals(1, validator.getErrorMessages().size());
     228        assertTrue(validator
     229                .getErrorMessages()
     230                .get(0)
     231                .startsWith(MDValidator.COMPONENT_NOT_REGISTERED_IN_APPROPRIATE_SPACE_ERROR));
     232
    241233        // make it user registry
    242234        testRegistry.setRegistryOwner(new OwnerUser(user.getId()));
    243         testRegistry.setRegistrySpace(RegistrySpace.PRIVATE);       
    244        
    245        
    246         validator = new MDValidator(new ByteArrayInputStream(
    247                 profileContent.getBytes()), desc, testRegistry,  marshaller);
    248         Boolean result =validator.validate();
    249         assertTrue(result);
    250         assertEquals(0, validator.getErrorMessages().size());
     235        testRegistry.setRegistrySpace(RegistrySpace.PRIVATE);
     236
     237        validator = new MDValidator(new ByteArrayInputStream(
     238                profileContent.getBytes()), desc, testRegistry, marshaller);
     239        Boolean result = validator.validate();
     240        assertTrue(result);
     241        assertEquals(0, validator.getErrorMessages().size());
    251242    }
    252243
    253244    @Test
    254245    public void testValidateNestedComponents() throws Exception {
    255         String id1 = "component1";
    256 
    257         String content = "";
    258         content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    259         content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    260         content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    261         content += "    <Header />\n";
    262         content += "    <CMD_Component name=\"Actor\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n";
    263         content += "        <CMD_Element name=\"Name\" ValueScheme=\"string\" />\n";
    264         content += "      <CMD_Component ComponentId=\""
    265                 + ComponentDescription.COMPONENT_PREFIX + id1 + "\"/>\n"; // id not
    266                                                                   // registered
    267         content += "    </CMD_Component>\n";
    268         content += "</CMD_ComponentSpec>\n";
    269 
    270         ComponentDescription desc = ComponentDescription.createNewDescription();
    271         MDValidator validator = new MDValidator(new ByteArrayInputStream(
    272                 content.getBytes()), desc, testRegistry, marshaller);
    273         assertFalse(validator.validate());
    274         assertEquals(1, validator.getErrorMessages().size());
    275         assertTrue(validator
    276                 .getErrorMessages()
    277                 .get(0)
    278                 .startsWith(MDValidator.COMPONENT_NOT_REGISTERED_ERROR));
    279 
    280         RegistryTestHelper.addComponent(testRegistry, id1, true);
    281         validator = new MDValidator(
    282                 new ByteArrayInputStream(content.getBytes()), desc,testRegistry, marshaller);
    283         assertTrue(validator.validate());
    284         assertEquals(0, validator.getErrorMessages().size());
     246        String id1 = "component1";
     247
     248        String content = "";
     249        content += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     250        content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     251        content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     252        content += "    <Header />\n";
     253        content += "    <CMD_Component name=\"Actor\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n";
     254        content += "        <CMD_Element name=\"Name\" ValueScheme=\"string\" />\n";
     255        content += "      <CMD_Component ComponentId=\""
     256                + ComponentDescription.COMPONENT_PREFIX + id1 + "\"/>\n"; // id not
     257        // registered
     258        content += "    </CMD_Component>\n";
     259        content += "</CMD_ComponentSpec>\n";
     260
     261        ComponentDescription desc = ComponentDescription.createNewDescription();
     262        MDValidator validator = new MDValidator(new ByteArrayInputStream(
     263                content.getBytes()), desc, testRegistry, marshaller);
     264        assertFalse(validator.validate());
     265        assertEquals(1, validator.getErrorMessages().size());
     266        assertTrue(validator
     267                .getErrorMessages()
     268                .get(0)
     269                .startsWith(MDValidator.COMPONENT_NOT_REGISTERED_ERROR));
     270
     271        RegistryTestHelper.addComponent(testRegistry, id1, true);
     272        validator = new MDValidator(
     273                new ByteArrayInputStream(content.getBytes()), desc, testRegistry, marshaller);
     274        assertTrue(validator.validate());
     275        assertEquals(0, validator.getErrorMessages().size());
    285276    }
    286277
     
    290281    @Test
    291282    public void testGetCMDComponentSpec() throws Exception {
    292         String profileContent = getValidProfileString();
    293         InputStream input = new ByteArrayInputStream(profileContent.getBytes());
    294 
    295         ProfileDescription desc = ProfileDescription.createNewDescription();
    296         MDValidator validator = new MDValidator(input, desc, testRegistry,marshaller);
    297 
    298         // Spec is created during validation, before it should be null
    299         assertNull(validator.getCMDComponentSpec());
    300         validator.validate();
    301 
    302         // Get spec created during validation
    303         final CMDComponentSpec cmdComponentSpec = validator
    304                 .getCMDComponentSpec();
    305         assertNotNull(cmdComponentSpec);
    306 
    307         // Spec content should match XML
    308         assertTrue(cmdComponentSpec.isIsProfile());
    309         assertEquals("Actor", cmdComponentSpec.getCMDComponent().getName());
    310 
    311         // Spec copy should be a freshly unmarshalled copy
    312         final CMDComponentSpec specCopy = validator.getCopyOfCMDComponentSpec();
    313         assertNotSame(cmdComponentSpec, specCopy);
    314 
    315         // Content should still match XML
    316         assertTrue(specCopy.isIsProfile());
    317         assertEquals("Actor", specCopy.getCMDComponent().getName());
     283        String profileContent = getValidProfileString();
     284        InputStream input = new ByteArrayInputStream(profileContent.getBytes());
     285
     286        ProfileDescription desc = ProfileDescription.createNewDescription();
     287        MDValidator validator = new MDValidator(input, desc, testRegistry, marshaller);
     288
     289        // Spec is created during validation, before it should be null
     290        assertNull(validator.getCMDComponentSpec());
     291        validator.validate();
     292
     293        // Get spec created during validation
     294        final CMDComponentSpec cmdComponentSpec = validator
     295                .getCMDComponentSpec();
     296        assertNotNull(cmdComponentSpec);
     297
     298        // Spec content should match XML
     299        assertTrue(cmdComponentSpec.isIsProfile());
     300        assertEquals("Actor", cmdComponentSpec.getCMDComponent().getName());
     301
     302        // Spec copy should be a freshly unmarshalled copy
     303        final CMDComponentSpec specCopy = validator.getCopyOfCMDComponentSpec();
     304        assertNotSame(cmdComponentSpec, specCopy);
     305
     306        // Content should still match XML
     307        assertTrue(specCopy.isIsProfile());
     308        assertEquals("Actor", specCopy.getCMDComponent().getName());
    318309    }
    319310
    320311    private MDValidator getValidProfileValidator() {
    321         final String profileContent = getValidProfileString();
    322         InputStream input = new ByteArrayInputStream(profileContent.getBytes());
    323         ProfileDescription desc = ProfileDescription.createNewDescription();
     312        final String profileContent = getValidProfileString();
     313        InputStream input = new ByteArrayInputStream(profileContent.getBytes());
     314        ProfileDescription desc = ProfileDescription.createNewDescription();
    324315        desc.setPublic(true);
    325316        desc.setName("test_name");
    326         MDValidator validator = new MDValidator(input, desc, testRegistry, marshaller);
    327         return validator;
     317        MDValidator validator = new MDValidator(input, desc, testRegistry, marshaller);
     318        return validator;
    328319    }
    329320
    330321    private String getValidProfileString() {
    331         String profileContent = "";
    332         profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    333         profileContent += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    334         profileContent += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    335         profileContent += "    <Header />\n";
    336         profileContent += "    <CMD_Component name=\"Actor\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n";
    337         profileContent += "        <CMD_Element name=\"Age\">\n";
    338         profileContent += "            <ValueScheme>\n";
    339         profileContent += "                <pattern>[23][0-9]</pattern>\n";
    340         profileContent += "            </ValueScheme>\n";
    341         profileContent += "        </CMD_Element>\n";
    342         profileContent += "    </CMD_Component>\n";
    343         profileContent += "</CMD_ComponentSpec>\n";
    344         return profileContent;
     322        String profileContent = "";
     323        profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     324        profileContent += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     325        profileContent += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     326        profileContent += "    <Header />\n";
     327        profileContent += "    <CMD_Component name=\"Actor\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n";
     328        profileContent += "        <CMD_Element name=\"Age\">\n";
     329        profileContent += "            <ValueScheme>\n";
     330        profileContent += "                <pattern>[23][0-9]</pattern>\n";
     331        profileContent += "            </ValueScheme>\n";
     332        profileContent += "        </CMD_Element>\n";
     333        profileContent += "    </CMD_Component>\n";
     334        profileContent += "</CMD_ComponentSpec>\n";
     335        return profileContent;
    345336    }
    346337}
Note: See TracChangeset for help on using the changeset viewer.