Ignore:
Timestamp:
08/18/14 14:22:07 (10 years ago)
Author:
olhsha@mpi.nl
Message:

Unit test for getting comments of profiles and components from groups.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/RegistryTestHelper.java

    r5556 r5560  
    2323import clarin.cmdi.componentregistry.model.ComponentDescription;
    2424import clarin.cmdi.componentregistry.model.ProfileDescription;
     25import clarin.cmdi.componentregistry.persistence.jpa.CommentsDao;
    2526
    2627import java.io.BufferedReader;
     
    2829import java.io.FileOutputStream;
    2930import java.io.InputStreamReader;
     31import java.util.Date;
    3032
    3133import org.springframework.beans.factory.annotation.Autowired;
     
    3840
    3941    private static MDMarshaller marshaller;
     42   
     43   
     44           
    4045
    4146    @Autowired
    4247    public void setMarshaller(MDMarshaller marshaller) {
    43         RegistryTestHelper.marshaller = marshaller;
    44     }
    45    
    46    
     48        RegistryTestHelper.marshaller = marshaller;
     49    }
    4750
    4851    public static ComponentDescription addComponent(ComponentRegistry testRegistry, String id, boolean isPublic) throws ParseException, JAXBException {
    49         return addComponent(testRegistry, id, getComponentTestContent(), isPublic);
    50     }
    51    
    52    
     52        return addComponent(testRegistry, id, getComponentTestContent(), isPublic);
     53    }
     54
    5355    public static ComponentDescription addComponent(ComponentRegistry testRegistry, String id, String content, boolean isPublic) throws ParseException,
    54             JAXBException, UnsupportedEncodingException {
    55         return addComponent(testRegistry, id, new ByteArrayInputStream(content.getBytes("UTF-8")), isPublic);
     56            JAXBException, UnsupportedEncodingException {
     57        return addComponent(testRegistry, id, new ByteArrayInputStream(content.getBytes("UTF-8")), isPublic);
    5658    }
    5759
    5860    private static ComponentDescription addComponent(ComponentRegistry testRegistry, String id, InputStream content, boolean isPublic) throws ParseException,
    59             JAXBException {
    60         ComponentDescription desc = ComponentDescription.createNewDescription();
    61         desc.setCreatorName(DummyPrincipal.DUMMY_CREDENTIALS.getDisplayName());
     61            JAXBException {
     62        ComponentDescription desc = ComponentDescription.createNewDescription();
     63        desc.setCreatorName(DummyPrincipal.DUMMY_CREDENTIALS.getDisplayName());
    6264        desc.setUserId(DummyPrincipal.DUMMY_PRINCIPAL.getName());
    63         desc.setName(id);
    64         desc.setDescription("Test Description");
    65         desc.setId(ComponentDescription.COMPONENT_PREFIX + id);
    66         desc.setHref("link:" + desc.getId());
     65        desc.setName(id);
     66        desc.setDescription("Test Description");
     67        desc.setId(ComponentDescription.COMPONENT_PREFIX + id);
     68        desc.setHref("link:" + desc.getId());
    6769        desc.setPublic(isPublic);
    68         CMDComponentSpec spec = marshaller.unmarshal(CMDComponentSpec.class, content, marshaller.getCMDComponentSchema());
    69         testRegistry.register(desc, spec);
    70         return desc;
    71     }
    72    
     70        CMDComponentSpec spec = marshaller.unmarshal(CMDComponentSpec.class, content, marshaller.getCMDComponentSchema());
     71        testRegistry.register(desc, spec);
     72        return desc;
     73    }
     74
    7375    public static ComponentDescription addComponentAnotherPrincipal(ComponentRegistry testRegistry, String id, boolean isPublic) throws ParseException, JAXBException {
    74         return addComponentAnotherPrincipal(testRegistry, id, getComponentTestContent(), isPublic);
    75     }
    76 
    77      private static ComponentDescription addComponentAnotherPrincipal(ComponentRegistry testRegistry, String id, InputStream content, boolean isPublic) throws ParseException,
    78             JAXBException {
    79         ComponentDescription desc = ComponentDescription.createNewDescription();
    80         desc.setCreatorName("AnotherPrincipal");
     76        return addComponentAnotherPrincipal(testRegistry, id, getComponentTestContent(), isPublic);
     77    }
     78
     79    private static ComponentDescription addComponentAnotherPrincipal(ComponentRegistry testRegistry, String id, InputStream content, boolean isPublic) throws ParseException,
     80            JAXBException {
     81        ComponentDescription desc = ComponentDescription.createNewDescription();
     82        desc.setCreatorName("AnotherPrincipal");
    8183        desc.setUserId("AnotherPrincipal");
    8284        desc.setDbUserId(2);
    83         desc.setName(id);
    84         desc.setDescription("Test Description");
    85         desc.setId(ComponentDescription.COMPONENT_PREFIX + id);
    86         desc.setHref("link:" + desc.getId());
     85        desc.setName(id);
     86        desc.setDescription("Test Description");
     87        desc.setId(ComponentDescription.COMPONENT_PREFIX + id);
     88        desc.setHref("link:" + desc.getId());
    8789        desc.setPublic(isPublic);
    88         CMDComponentSpec spec = marshaller.unmarshal(CMDComponentSpec.class, content, marshaller.getCMDComponentSchema());
    89         testRegistry.register(desc, spec);
    90         return desc;
     90        CMDComponentSpec spec = marshaller.unmarshal(CMDComponentSpec.class, content, marshaller.getCMDComponentSchema());
     91        testRegistry.register(desc, spec);
     92        return desc;
    9193    }
    9294
    9395    public static String getProfileTestContentString() {
    94         return getProfileTestContentString("Actor");
     96        return getProfileTestContentString("Actor");
    9597    }
    9698
    9799    private static String getProfileTestContentString(String name) {
    98         String profileContent = "";
    99         profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    100         profileContent += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    101         profileContent += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    102         profileContent += "    <Header />\n";
    103         profileContent += "    <CMD_Component name=\"" + name + "\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n";
    104         profileContent += "        <AttributeList>\n";
    105         profileContent += "            <Attribute>\n";
    106         profileContent += "                <Name>Name</Name>\n";
    107         profileContent += "                <Type>string</Type>\n";
    108         profileContent += "            </Attribute>\n";
    109         profileContent += "        </AttributeList>\n";
    110         profileContent += "        <CMD_Element name=\"Age\">\n";
    111         profileContent += "            <ValueScheme>\n";
    112         profileContent += "                <pattern>[23][0-9]</pattern>\n";
    113         profileContent += "            </ValueScheme>\n";
    114         profileContent += "        </CMD_Element>\n";
    115         profileContent += "    </CMD_Component>\n";
    116         profileContent += "</CMD_ComponentSpec>\n";
    117         return profileContent;
     100        String profileContent = "";
     101        profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     102        profileContent += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     103        profileContent += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     104        profileContent += "    <Header />\n";
     105        profileContent += "    <CMD_Component name=\"" + name + "\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n";
     106        profileContent += "        <AttributeList>\n";
     107        profileContent += "            <Attribute>\n";
     108        profileContent += "                <Name>Name</Name>\n";
     109        profileContent += "                <Type>string</Type>\n";
     110        profileContent += "            </Attribute>\n";
     111        profileContent += "        </AttributeList>\n";
     112        profileContent += "        <CMD_Element name=\"Age\">\n";
     113        profileContent += "            <ValueScheme>\n";
     114        profileContent += "                <pattern>[23][0-9]</pattern>\n";
     115        profileContent += "            </ValueScheme>\n";
     116        profileContent += "        </CMD_Element>\n";
     117        profileContent += "    </CMD_Component>\n";
     118        profileContent += "</CMD_ComponentSpec>\n";
     119        return profileContent;
    118120    }
    119121
    120122    public static InputStream getTestProfileContent() {
    121         return getTestProfileContent("Actor");
     123        return getTestProfileContent("Actor");
    122124    }
    123125
    124126    public static InputStream getTestProfileContent(String name) {
    125         return new ByteArrayInputStream(getProfileTestContentString(name).getBytes());
     127        return new ByteArrayInputStream(getProfileTestContentString(name).getBytes());
    126128    }
    127129
    128130    public static ProfileDescription addProfile(ComponentRegistry testRegistry, String id, boolean isPublic) throws ParseException, JAXBException, ItemNotFoundException {
    129         return addProfile(testRegistry, id, RegistryTestHelper.getTestProfileContent(), isPublic);
     131        return addProfile(testRegistry, id, RegistryTestHelper.getTestProfileContent(), isPublic);
    130132    }
    131133
    132134    public static ProfileDescription addProfile(ComponentRegistry testRegistry, String id, String content, boolean isPublic) throws ParseException,
    133             JAXBException, ItemNotFoundException {
    134         return addProfile(testRegistry, id, new ByteArrayInputStream(content.getBytes()), isPublic);
    135     }
    136    
    137    
     135            JAXBException, ItemNotFoundException {
     136        return addProfile(testRegistry, id, new ByteArrayInputStream(content.getBytes()), isPublic);
     137    }
    138138
    139139    private static ProfileDescription addProfile(ComponentRegistry testRegistry, String id, InputStream content, boolean isPublic) throws ParseException,
    140             JAXBException, ItemNotFoundException {
    141         ProfileDescription desc = ProfileDescription.createNewDescription();
    142         desc.setCreatorName(DummyPrincipal.DUMMY_CREDENTIALS.getDisplayName());
    143         desc.setUserId(DummyPrincipal.DUMMY_CREDENTIALS.getPrincipalName());
    144         desc.setName(id);
    145         desc.setDescription("Test Description");
    146         desc.setId(ProfileDescription.PROFILE_PREFIX + id);
    147         desc.setHref("link:" + ProfileDescription.PROFILE_PREFIX + id);
     140            JAXBException, ItemNotFoundException {
     141        ProfileDescription desc = ProfileDescription.createNewDescription();
     142        desc.setCreatorName(DummyPrincipal.DUMMY_CREDENTIALS.getDisplayName());
     143        desc.setUserId(DummyPrincipal.DUMMY_CREDENTIALS.getPrincipalName());
     144        desc.setName(id);
     145        desc.setDescription("Test Description");
     146        desc.setId(ProfileDescription.PROFILE_PREFIX + id);
     147        desc.setHref("link:" + ProfileDescription.PROFILE_PREFIX + id);
    148148        desc.setPublic(isPublic);
    149         CMDComponentSpec spec = marshaller.unmarshal(CMDComponentSpec.class, content, marshaller.getCMDComponentSchema());
    150         testRegistry.register(desc, spec);
    151         return desc;
    152     }
    153    
     149        CMDComponentSpec spec = marshaller.unmarshal(CMDComponentSpec.class, content, marshaller.getCMDComponentSchema());
     150        testRegistry.register(desc, spec);
     151        return desc;
     152    }
     153
    154154    public static ProfileDescription addProfileAnotherPrincipal(ComponentRegistry testRegistry, String id, boolean isPublic) throws ParseException, JAXBException, ItemNotFoundException {
    155         return addProfileAnotherPrincipal(testRegistry, id, RegistryTestHelper.getTestProfileContent(), isPublic);
    156     }
    157    
     155        return addProfileAnotherPrincipal(testRegistry, id, RegistryTestHelper.getTestProfileContent(), isPublic);
     156    }
     157
    158158    private static ProfileDescription addProfileAnotherPrincipal(ComponentRegistry testRegistry, String id, InputStream content, boolean isPublic) throws ParseException,
    159             JAXBException, ItemNotFoundException {
    160         ProfileDescription desc = ProfileDescription.createNewDescription();
    161         desc.setCreatorName("AnotherPrincipal");
    162         desc.setUserId("AnotherPrincipal");
     159            JAXBException, ItemNotFoundException {
     160        ProfileDescription desc = ProfileDescription.createNewDescription();
     161        desc.setCreatorName("AnotherPrincipal");
     162        desc.setUserId("AnotherPrincipal");
    163163        desc.setDbUserId(2);
    164         desc.setName(id);
    165         desc.setDescription("Test Description");
    166         desc.setId(ProfileDescription.PROFILE_PREFIX + id);
    167         desc.setHref("link:" + ProfileDescription.PROFILE_PREFIX + id);
     164        desc.setName(id);
     165        desc.setDescription("Test Description");
     166        desc.setId(ProfileDescription.PROFILE_PREFIX + id);
     167        desc.setHref("link:" + ProfileDescription.PROFILE_PREFIX + id);
    168168        desc.setPublic(isPublic);
    169         CMDComponentSpec spec = marshaller.unmarshal(CMDComponentSpec.class, content, marshaller.getCMDComponentSchema());
    170         testRegistry.register(desc, spec);
    171         return desc;
     169        CMDComponentSpec spec = marshaller.unmarshal(CMDComponentSpec.class, content, marshaller.getCMDComponentSchema());
     170        testRegistry.register(desc, spec);
     171        return desc;
    172172    }
    173173
    174174    public static CMDComponentSpec getTestProfile() throws JAXBException {
    175         return marshaller.unmarshal(CMDComponentSpec.class, getTestProfileContent(), marshaller.getCMDComponentSchema());
     175        return marshaller.unmarshal(CMDComponentSpec.class, getTestProfileContent(), marshaller.getCMDComponentSchema());
    176176    }
    177177
    178178    public static String getComponentTestContentString() {
    179         return getComponentTestContentString("Access");
     179        return getComponentTestContentString("Access");
    180180    }
    181181
    182182    public static InputStream getComponentTestContent() {
    183         return getComponentTestContentAsStream("Access");
     183        return getComponentTestContentAsStream("Access");
    184184    }
    185185
    186186    public static String getComponentTestContentString(String componentName) {
    187         String compContent = "";
    188         compContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    189         compContent += "\n";
    190         compContent += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    191         compContent += "    xsi:noNamespaceSchemaLocation=\"../../general-component-schema.xsd\">\n";
    192         compContent += "    \n";
    193         compContent += "    <Header/>\n";
    194         compContent += "    \n";
    195         compContent += "    <CMD_Component name=\"" + componentName + "\" CardinalityMin=\"1\" CardinalityMax=\"1\">\n";
    196         compContent += "        <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n";
    197         compContent += "        <CMD_Element name=\"Date\">\n";
    198         compContent += "            <ValueScheme>\n";
    199         compContent += "                <!-- matching dates of the pattern yyyy-mm-dd (ISO 8601); this only matches dates from the years 1000 through 2999 and does allow some invalid dates (e.g. February, the 30th) -->\n";
    200         compContent += "                <pattern>(1|2)\\d{3}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])</pattern>                \n";
    201         compContent += "            </ValueScheme>\n";
    202         compContent += "        </CMD_Element>\n";
    203         compContent += "        <CMD_Element name=\"Owner\" ValueScheme=\"string\" />\n";
    204         compContent += "        <CMD_Element name=\"Publisher\" ValueScheme=\"string\" />\n";
    205         compContent += "    </CMD_Component>\n";
    206         compContent += "\n";
    207         compContent += "</CMD_ComponentSpec>\n";
    208         return compContent;
     187        String compContent = "";
     188        compContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     189        compContent += "\n";
     190        compContent += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     191        compContent += "    xsi:noNamespaceSchemaLocation=\"../../general-component-schema.xsd\">\n";
     192        compContent += "    \n";
     193        compContent += "    <Header/>\n";
     194        compContent += "    \n";
     195        compContent += "    <CMD_Component name=\"" + componentName + "\" CardinalityMin=\"1\" CardinalityMax=\"1\">\n";
     196        compContent += "        <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n";
     197        compContent += "        <CMD_Element name=\"Date\">\n";
     198        compContent += "            <ValueScheme>\n";
     199        compContent += "                <!-- matching dates of the pattern yyyy-mm-dd (ISO 8601); this only matches dates from the years 1000 through 2999 and does allow some invalid dates (e.g. February, the 30th) -->\n";
     200        compContent += "                <pattern>(1|2)\\d{3}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])</pattern>                \n";
     201        compContent += "            </ValueScheme>\n";
     202        compContent += "        </CMD_Element>\n";
     203        compContent += "        <CMD_Element name=\"Owner\" ValueScheme=\"string\" />\n";
     204        compContent += "        <CMD_Element name=\"Publisher\" ValueScheme=\"string\" />\n";
     205        compContent += "    </CMD_Component>\n";
     206        compContent += "\n";
     207        compContent += "</CMD_ComponentSpec>\n";
     208        return compContent;
    209209    }
    210210
    211211    public static String getStringFromStream(InputStream largeProfileStream) throws IOException {
    212         try {
    213             BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(largeProfileStream));
    214             StringBuilder profileStringBuilder = new StringBuilder();
    215             String line;
    216             while (null != (line = bufferedReader.readLine())) {
    217                 profileStringBuilder.append(line);
    218             }
    219             return profileStringBuilder.toString();
    220         } finally {
    221             largeProfileStream.close();
    222         }
     212        try {
     213            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(largeProfileStream));
     214            StringBuilder profileStringBuilder = new StringBuilder();
     215            String line;
     216            while (null != (line = bufferedReader.readLine())) {
     217                profileStringBuilder.append(line);
     218            }
     219            return profileStringBuilder.toString();
     220        } finally {
     221            largeProfileStream.close();
     222        }
    223223    }
    224224    ///////////////////////////////////////////////////////
    225225
    226226    public static String getLargeProfileContent() throws IOException {
    227         InputStream largeProfileStream = RegistryTestHelper.class.getResourceAsStream("/xml/largeProfile.xml");
    228         return getStringFromStream(largeProfileStream);
     227        InputStream largeProfileStream = RegistryTestHelper.class.getResourceAsStream("/xml/largeProfile.xml");
     228        return getStringFromStream(largeProfileStream);
    229229    }
    230230
    231231    //////////////////////
    232232    public static CMDComponentSpec getComponentFromString(String contentString) throws JAXBException {
    233         return marshaller.unmarshal(CMDComponentSpec.class, getComponentContentAsStream(contentString), marshaller.getCMDComponentSchema());
     233        return marshaller.unmarshal(CMDComponentSpec.class, getComponentContentAsStream(contentString), marshaller.getCMDComponentSchema());
    234234    }
    235235
    236236    public static InputStream getComponentContentAsStream(String content) {
    237         return new ByteArrayInputStream(content.getBytes());
     237        return new ByteArrayInputStream(content.getBytes());
    238238    }
    239239
    240240    public static InputStream getComponentTestContentAsStream(String componentName) {
    241         return getComponentContentAsStream(getComponentTestContentString(componentName));
     241        return getComponentContentAsStream(getComponentTestContentString(componentName));
    242242    }
    243243
    244244    public static CMDComponentSpec getTestComponent() throws JAXBException {
    245         return marshaller.unmarshal(CMDComponentSpec.class, getComponentTestContent(), marshaller.getCMDComponentSchema());
     245        return marshaller.unmarshal(CMDComponentSpec.class, getComponentTestContent(), marshaller.getCMDComponentSchema());
    246246    }
    247247
    248248    public static CMDComponentSpec getTestComponent(String name) throws JAXBException {
    249         return marshaller.unmarshal(CMDComponentSpec.class, getComponentTestContentAsStream(name), marshaller.getCMDComponentSchema());
     249        return marshaller.unmarshal(CMDComponentSpec.class, getComponentTestContentAsStream(name), marshaller.getCMDComponentSchema());
    250250    }
    251251
    252252    public static String getXml(CMDComponentSpec componentSpec) throws JAXBException, UnsupportedEncodingException {
    253         ByteArrayOutputStream os = new ByteArrayOutputStream();
    254         marshaller.marshal(componentSpec, os);
    255         String xml = os.toString();
    256         try {
    257             os.close();
    258         } catch (IOException ex) {
    259         }
    260         return xml;
    261     }
    262 
    263     public static Comment addComment(ComponentRegistry testRegistry, String id, String descriptionId, String principal) throws ParseException, JAXBException, ComponentRegistryException, ItemNotFoundException,UserUnauthorizedException {
    264         return addComment(testRegistry, RegistryTestHelper.getTestCommentContent(id, descriptionId), principal);
     253        ByteArrayOutputStream os = new ByteArrayOutputStream();
     254        marshaller.marshal(componentSpec, os);
     255        String xml = os.toString();
     256        try {
     257            os.close();
     258        } catch (IOException ex) {
     259        }
     260        return xml;
     261    }
     262
     263    public static Comment addComment(ComponentRegistry testRegistry, String id, String descriptionId, String principal) throws ParseException, JAXBException, ComponentRegistryException, ItemNotFoundException, UserUnauthorizedException {
     264        return addComment(testRegistry, RegistryTestHelper.getTestCommentContent(id, descriptionId), principal);
    265265    }
    266266
    267267    private static Comment addComment(ComponentRegistry testRegistry, InputStream content, String principal) throws ParseException,
    268             JAXBException,
    269             ComponentRegistryException, ItemNotFoundException,UserUnauthorizedException {
    270         Comment spec = marshaller.unmarshal(Comment.class, content, null);
    271         testRegistry.registerComment(spec, principal);
    272         return spec;
     268            JAXBException,
     269            ComponentRegistryException, ItemNotFoundException, UserUnauthorizedException {
     270        Comment spec = marshaller.unmarshal(Comment.class, content, null);
     271        testRegistry.registerComment(spec, principal);
     272        return spec;
     273    }
     274   
     275    public Comment addCommentBypassAuthorisation(CommentsDao commentsDao, String id, String descriptionId, String principal) throws ParseException, JAXBException, ComponentRegistryException, ItemNotFoundException, UserUnauthorizedException {
     276        return addCommentBypassAuthorisation(commentsDao, RegistryTestHelper.getTestCommentContent(id, descriptionId), principal);
     277    }
     278
     279
     280    private Comment addCommentBypassAuthorisation(CommentsDao commentsDao, InputStream content, String principal) throws ParseException,
     281            JAXBException,
     282            ComponentRegistryException, ItemNotFoundException, UserUnauthorizedException {
     283        Comment comment = marshaller.unmarshal(Comment.class, content, null);
     284        comment.setCommentDate(new Date());
     285        comment.setUserId(2);
     286        commentsDao.saveAndFlush(comment);
     287        return comment;
    273288    }
    274289
    275290    public static String getCommentTestContentStringForProfile(String commentName, String profileId) {
    276         String comContent = "";
    277         comContent += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
    278         comContent += "<comment xmlns:ns2=\"http://www.w3.org/1999/xlink\">\n";
    279         comContent += "    <comments>" + commentName + "</comments>\n";
    280         comContent += "    <commentDate>" + DatesHelper.createNewDate() + "</commentDate>\n";
    281         comContent += "    <componentId>" + profileId + "</componentId>\n";
    282         comContent += "    <userName>J. Unit</userName>\n";
    283         comContent += "</comment>\n";
    284         return comContent;
     291        String comContent = "";
     292        comContent += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
     293        comContent += "<comment xmlns:ns2=\"http://www.w3.org/1999/xlink\">\n";
     294        comContent += "    <comments>" + commentName + "</comments>\n";
     295        comContent += "    <commentDate>" + DatesHelper.createNewDate() + "</commentDate>\n";
     296        comContent += "    <componentId>" + profileId + "</componentId>\n";
     297        comContent += "    <userName>JUnit@test.com</userName>\n";
     298        comContent += "</comment>\n";
     299        return comContent;
     300    }
     301   
     302     public static String getanotherPrincipalCommentTestContentStringForProfile(String commentName, String profileId) {
     303        String comContent = "";
     304        comContent += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
     305        comContent += "<comment xmlns:ns2=\"http://www.w3.org/1999/xlink\">\n";
     306        comContent += "    <comments>" + commentName + "</comments>\n";
     307        comContent += "    <commentDate>" + DatesHelper.createNewDate() + "</commentDate>\n";
     308        comContent += "    <componentId>" + profileId + "</componentId>\n";
     309        comContent += "    <userName>anotherPrincipal</userName>\n";
     310        comContent += "</comment>\n";
     311        return comContent;
    285312    }
    286313
    287314    public static String getCommentTestContentStringForComponent(String commentName, String componentId) {
    288         String comContent = "";
    289         comContent += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
    290         comContent += "<comment xmlns:ns2=\"http://www.w3.org/1999/xlink\">\n";
    291         comContent += "    <comments>" + commentName + "</comments>\n";
    292         comContent += "    <commentDate>" + DatesHelper.createNewDate() + "</commentDate>\n";
    293         comContent += "     <componentId>" + componentId + "</componentId>";
    294         comContent += "    <userName>J. Unit</userName>\n";
    295         comContent += "</comment>\n";
    296         return comContent;
     315        String comContent = "";
     316        comContent += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
     317        comContent += "<comment xmlns:ns2=\"http://www.w3.org/1999/xlink\">\n";
     318        comContent += "    <comments>" + commentName + "</comments>\n";
     319        comContent += "    <commentDate>" + DatesHelper.createNewDate() + "</commentDate>\n";
     320        comContent += "     <componentId>" + componentId + "</componentId>";
     321        comContent += "    <userName>JUnit@test.com</userName>\n";
     322        comContent += "</comment>\n";
     323        return comContent;
     324    }
     325   
     326     public static String getAnotherPrincipalCommentTestContentStringForComponent(String commentName, String componentId) {
     327        String comContent = "";
     328        comContent += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
     329        comContent += "<comment xmlns:ns2=\"http://www.w3.org/1999/xlink\">\n";
     330        comContent += "    <comments>" + commentName + "</comments>\n";
     331        comContent += "    <commentDate>" + DatesHelper.createNewDate() + "</commentDate>\n";
     332        comContent += "     <componentId>" + componentId + "</componentId>";
     333        comContent += "    <userName>anotherPrincipal</userName>\n";
     334        comContent += "</comment>\n";
     335        return comContent;
    297336    }
    298337
    299338    public static InputStream getTestCommentContent(String content, String descriptionId) {
    300         if (descriptionId.contains("profile")) {
    301             return new ByteArrayInputStream(getCommentTestContentStringForProfile(content, descriptionId).getBytes());
    302         } else {
    303             return new ByteArrayInputStream(getCommentTestContentStringForComponent(content, descriptionId).getBytes());
    304         }
     339        if (descriptionId.contains("profile")) {
     340            return new ByteArrayInputStream(getCommentTestContentStringForProfile(content, descriptionId).getBytes());
     341        } else {
     342            return new ByteArrayInputStream(getCommentTestContentStringForComponent(content, descriptionId).getBytes());
     343        }
    305344    }
    306345
    307346    public static String getCommentTestContent(String commentId, String descriptionId) {
    308         return getCommentTestContentStringForProfile(commentId, descriptionId);
     347        return getCommentTestContentStringForProfile(commentId, descriptionId);
    309348    }
    310349
    311350    public static InputStream getCommentTestContent() {
    312         return getTestCommentContent("Actual", ProfileDescription.PROFILE_PREFIX+"profile1");
    313     }
    314 
    315     /**
    316      * Testing a big xsd string is a bit hard, so doing a best effort by checking the xs:element which represent the nested components used
    317      * in a profile/component
     351        return getTestCommentContent("Actual", ProfileDescription.PROFILE_PREFIX + "profile1");
     352    }
     353
     354    /**
     355     * Testing a big xsd string is a bit hard, so doing a best effort by
     356     * checking the xs:element which represent the nested components used in a
     357     * profile/component
    318358     */
    319359    public static boolean hasComponent(String xsd, String name, String min, String max) {
    320         Pattern pattern = Pattern.compile("<xs:element name=\"" + name + "\" minOccurs=\"" + min + "\" maxOccurs=\"" + max + "\">");
    321         Matcher matcher = pattern.matcher(xsd);
    322         return matcher.find() && !matcher.find(); //find only one
     360        Pattern pattern = Pattern.compile("<xs:element name=\"" + name + "\" minOccurs=\"" + min + "\" maxOccurs=\"" + max + "\">");
     361        Matcher matcher = pattern.matcher(xsd);
     362        return matcher.find() && !matcher.find(); //find only one
    323363    }
    324364
    325365    /**
    326366     *
    327      * @param bytes is an array of bytes to be written in the file filename (from scratch!)
    328      * @param filename is the name of the file where the array "bytes" is to be written to
     367     * @param bytes is an array of bytes to be written in the file filename
     368     * (from scratch!)
     369     * @param filename is the name of the file where the array "bytes" is to be
     370     * written to
    329371     * @throws IOException
    330372     * @throws JAXBException
     
    332374    public static void writeBytesToFile(byte[] bytes, String filename) throws IOException, JAXBException {
    333375
    334         File file = new File(filename);
    335         FileOutputStream fop = new FileOutputStream(file);
    336 
    337         fop.write(bytes);
    338 
    339         fop.flush();
    340         fop.close();
     376        File file = new File(filename);
     377        FileOutputStream fop = new FileOutputStream(file);
     378
     379        fop.write(bytes);
     380
     381        fop.flush();
     382        fop.close();
    341383
    342384
     
    345387    /**
    346388     *
    347      * @param str is a string which is to be written into the filename (from scratch!)
     389     * @param str is a string which is to be written into the filename (from
     390     * scratch!)
    348391     * @param filename is a filename where the string is to be written to
    349392     * @throws IOException
     
    352395    public static void writeStringToFile(String str, String filename) throws IOException, JAXBException {
    353396
    354         writeBytesToFile(str.getBytes(), filename);
     397        writeBytesToFile(str.getBytes(), filename);
    355398
    356399
     
    359402    /**
    360403     *
    361      * @param os is an output stream which is to be written into the filename (from scratch!)
     404     * @param os is an output stream which is to be written into the filename
     405     * (from scratch!)
    362406     * @param filename is a filename where the stream is to be written to
    363407     * @throws IOException
     
    366410    public static void writeStreamToFile(ByteArrayOutputStream os, String filename) throws IOException, JAXBException {
    367411
    368         writeBytesToFile(os.toByteArray(), filename);
     412        writeBytesToFile(os.toByteArray(), filename);
    369413
    370414
     
    373417    /**
    374418     *
    375      * @param cdesc is a component which is to be written into the filename (from scratch!)
     419     * @param cdesc is a component which is to be written into the filename
     420     * (from scratch!)
    376421     * @param filename is a filename where the component is to be written to
    377422     * @throws IOException
     
    381426
    382427
    383         ByteArrayOutputStream os = new ByteArrayOutputStream();
    384         marshaller.marshal(cdesc, os);
    385 
    386         writeStreamToFile(os, filename);
     428        ByteArrayOutputStream os = new ByteArrayOutputStream();
     429        marshaller.marshal(cdesc, os);
     430
     431        writeStreamToFile(os, filename);
    387432
    388433    }
     
    391436     * opens a temporary sub-directory dirName in /target/
    392437     *
    393      * @param dirName is the name of the temporary subdirectory which is to be opened
     438     * @param dirName is the name of the temporary subdirectory which is to be
     439     * opened
    394440     * @return the absolute part for this directory
    395441     */
    396442    public static String openTestDir(String dirName) {
    397443
    398         File testDir = new File("target/" + dirName);
    399 
    400 
    401         testDir.mkdir();
    402 
    403         System.out.println(dirName);
    404         //String retval = new File(testDir, dirName).getAbsolutePath();
    405         String retval = new File(testDir, "/").getAbsolutePath();
    406 
    407         return (retval);
     444        File testDir = new File("target/" + dirName);
     445
     446
     447        testDir.mkdir();
     448
     449        System.out.println(dirName);
     450        //String retval = new File(testDir, dirName).getAbsolutePath();
     451        String retval = new File(testDir, "/").getAbsolutePath();
     452
     453        return (retval);
    408454
    409455    }
Note: See TracChangeset for help on using the changeset viewer.