Changeset 1635


Ignore:
Timestamp:
12/01/11 15:04:15 (12 years ago)
Author:
jeafer
Message:

Jean-Charles branch commit3,
Changes regarding comment on the ComponentRegistry service.
Delete_comment from RestService? to Database access (CommentsDao?) implemented.
Post_comment from RestService? to Database access (CommentsDao?) implemented. (Not yet tested)
Comment class updated
CommentsDao? updated
CommentTest? class implemented (New Class)
Test classes ComponentRegistryRestServiceTest? and RegistryHelperTest? starting to implement tests for Comment validation (insertion, deletion)

Location:
ComponentRegistry/branches/jeaferversion/ComponentRegistry/src
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/ComponentRegistry.java

    r1633 r1635  
    5656    int register(AbstractDescription desc, CMDComponentSpec spec);
    5757
     58   
     59    int registerComment(Comment comment, Comment spec);
    5860    /**
    5961     *
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/ComponentRegistryImplBase.java

    r1633 r1635  
    2020import clarin.cmdi.componentregistry.components.CMDComponentSpec.Header;
    2121import clarin.cmdi.componentregistry.model.AbstractDescription;
     22import clarin.cmdi.componentregistry.model.Comment;
    2223import clarin.cmdi.componentregistry.model.ComponentDescription;
    2324import clarin.cmdi.componentregistry.model.ProfileDescription;
     
    106107        }
    107108    }
    108 
     109       
    109110    protected static boolean findComponentId(String componentId, List<CMDComponentType> componentReferences) {
    110111        for (CMDComponentType cmdComponent : componentReferences) {
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/CommentsDao.java

    r1633 r1635  
    1212import java.sql.Timestamp;
    1313import java.text.ParseException;
     14import java.util.Collections;
    1415import java.util.HashMap;
    1516import java.util.List;
     
    9798     */
    9899    public String getOwnerPrincipalName(Number id) {
    99         StringBuilder select = new StringBuilder("SELECT principal_name FROM " + TABLE_REGISTRY_USER);
    100         select.append(" JOIN ").append(getTableName());
    101         select.append(" ON user_id = " + TABLE_REGISTRY_USER + ".id ");
    102         select.append(" WHERE ").append(getTableName()).append(".id = ?");
    103         List<String> owner = getSimpleJdbcTemplate().query(select.toString(), new ParameterizedSingleColumnRowMapper<String>(), id);
    104         if (owner.isEmpty()) {
    105             return null;
    106         } else {
    107             return owner.get(0);
    108         }
    109     }
     100        StringBuilder select = new StringBuilder("SELECT principal_name FROM " + TABLE_REGISTRY_USER);
     101        select.append(" JOIN ").append(getTableName());
     102        select.append(" ON user_id = " + TABLE_REGISTRY_USER + ".id ");
     103        select.append(" WHERE ").append(getTableName()).append(".id = ?");
     104        List<String> owner = getSimpleJdbcTemplate().query(select.toString(), new ParameterizedSingleColumnRowMapper<String>(), id);
     105        if (owner.isEmpty()) {
     106            return null;
     107        } else {
     108            return owner.get(0);
     109        }
     110    }
     111
    110112    /**
    111113     *
     
    114116     * @throws DataAccessException
    115117     */
    116     public Number insertComment(Comment comment) throws DataAccessException {
    117         SimpleJdbcInsert insert = new SimpleJdbcInsert(getDataSource()).withTableName(TABLE_COMMENTS).usingGeneratedKeyColumns(
    118                 COLUMN_ID);
    119 
    120         Map<String, Object> params = new HashMap<String, Object>();
     118    public Number insertComment(Comment comment, String content, Number userId) throws DataAccessException {
     119        TransactionStatus transaction = getTransaction();
     120        try {
     121            SimpleJdbcInsert insert = new SimpleJdbcInsert(getDataSource()).withTableName(TABLE_COMMENTS).usingGeneratedKeyColumns(
     122                    COLUMN_ID);
     123            //Number contentId = insert.executeAndReturnKey(Collections.singletonMap("content", (Object) content));
     124
     125            SimpleJdbcInsert insertComment = new SimpleJdbcInsert(getDataSource()).withTableName(getTableName()).usingGeneratedKeyColumns(COLUMN_ID);
     126            Map<String, Object> params = new HashMap<String, Object>();
     127            putInsertComment(params, comment, content, userId);
     128
     129            Number id = insertComment.executeAndReturnKey(params);
     130            txManager.commit(transaction);
     131            return id;
     132        } catch (DataAccessException ex) {
     133            txManager.rollback(transaction);
     134            throw ex;
     135        }
     136    }
     137
     138    protected void putInsertComment(Map<String, Object> params, Comment comment, String contentId, Number userId) throws DataAccessException {
     139        // SimpleJdbcInsert insert = new SimpleJdbcInsert(getDataSource()).withTableName(TABLE_COMMENTS).usingGeneratedKeyColumns(
     140        //         COLUMN_ID);
    121141        params.put("comments", comment.getComment());
    122142        params.put("comment_date", extractTimestamp(comment));
     
    124144        params.put("profile_description_id", comment.getProfileDescriptionId());
    125145        params.put("user_id", comment.getUserId());
    126         return insert.executeAndReturnKey(params);
    127146    }
    128147
     
    181200        return getSimpleJdbcTemplate().queryForInt(query.toString(), cmdId);
    182201    }
     202//    public Comment getDbId(Number cmId) {
     203//        return getFirstOrNull(getSelectStatement("WHERE id=?"), cmId);
     204//    }
     205//
     206//    private StringBuilder getSelectStatement(String... where) throws DataAccessException {
     207//        StringBuilder select = new StringBuilder("SELECT ").append(getCommentColumnList());
     208//        select.append(" FROM ").append(getTableName());
     209//        if (where.length > 0) {
     210//            select.append(" ");
     211//            for (String str : where) {
     212//                select.append(" ").append(str);
     213//            }
     214//        }
     215//        return select;
     216//    }
     217//
     218//    protected StringBuilder getCommentColumnList() {
     219//
     220//        StringBuilder sb = new StringBuilder();
     221//        sb.append(getOrderByColumn());
     222//        sb.append(",comment,comment_date,user_id,");
     223//        return sb;
     224//    }
     225//
     226//    private String getOrderByColumn() {
     227//        return "name";
     228//    }
    183229
    184230    private Timestamp extractTimestamp(Comment comment) {
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java

    r1633 r1635  
    230230        }
    231231    }
     232   
     233    @Override
     234    public int registerComment(Comment comment, Comment spec){
     235        try {
     236            String xml = commmentSpecToString(spec);
     237            // Convert principal name to user record id
     238            Number uid = convertUserIdInComment(comment);
     239            commentsDao.insertComment(comment, xml, uid);
     240            return 0;
     241        } catch (DataAccessException ex) {
     242            LOG.error("Database error while registering component", ex);
     243            return -1;
     244        } catch (JAXBException ex) {
     245            LOG.error("Error while registering component", ex);
     246            return -2;
     247        } catch (UnsupportedEncodingException ex) {
     248            LOG.error("Error while registering component", ex);
     249            return -3;
     250        }
     251    }
    232252
    233253    /**
     
    253273        if (uid != null) {
    254274            description.setUserId(uid.toString());
     275        }
     276        return uid;
     277    }
     278   
     279        private Number convertUserIdInComment(Comment comment) throws DataAccessException {
     280        Number uid = null;
     281        if (comment.getUserId() != null) {
     282            User user = userDao.getByPrincipalName(comment.getUserId());
     283            if (user != null) {
     284                uid = user.getId();
     285            }
     286        } else {
     287            uid = userId;
     288        }
     289        if (uid != null) {
     290            comment.setUserId(uid.toString());
    255291        }
    256292        return uid;
     
    460496        return xml;
    461497    }
     498   
     499        private String commmentSpecToString(Comment spec) throws UnsupportedEncodingException, JAXBException {
     500        ByteArrayOutputStream os = new ByteArrayOutputStream();
     501        MDMarshaller.marshal(spec, os);
     502        String xml = os.toString("UTF-8");
     503        return xml;
     504    }
    462505
    463506    private CMDComponentSpec getUncachedMDComponent(String id, AbstractDescriptionDao dao) {
     
    523566    }
    524567
    525     private void checkCommentAge(Comment desc, Principal principal) throws DeleteFailedException {
    526         if (isPublic() && !configuration.isAdminUser(principal)) {
    527             try {
    528                 Date regDate = Comment.getDate(desc.getCommentDate());
    529                 Calendar calendar = Calendar.getInstance();
    530                 calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
    531                 if (regDate.before(calendar.getTime())) { // More then month old
    532                     throw new DeleteFailedException(
    533                             "The "
    534                             + (desc.getId())
    535                             + " is more then a month old and cannot be deleted anymore.");
    536                 }
    537             } catch (ParseException e) {
    538                 LOG.error("Cannot parse date of " + desc + " Error:" + e);
    539             }
    540         }
    541     }
    542 
    543568    private boolean inWorkspace(AbstractDescriptionDao<?> dao, String cmdId) {
    544569        if (isPublic()) {
     
    549574    }
    550575
    551 //    private boolean inWorkspace(CommentsDao dao, String cmdId) {
    552 //        if (isPublic()) {
    553 //            return dao.isPublic(cmdId);
    554 //        } else {
    555 //            return dao.isInUserSpace(cmdId, getUserId());
    556 //        }
    557 //    }
    558576    @Override
    559577    public String getName() {
     
    583601            try {
    584602                    checkAuthorisationComment(com, principal);
    585                     checkCommentAge(com, principal);
    586603                    commentsDao.deleteComment(com, true);
    587604                } catch (DataAccessException ex) {
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/model/Comment.java

    r1633 r1635  
    103103       
    104104            public static Comment createANewComment() {
    105         String id = ComponentRegistry.REGISTRY_ID + "p_" + IdSequence.get();
     105        String descriptionId = ComponentRegistry.REGISTRY_ID+ "p_" + IdSequence.get();
    106106        Comment com = new Comment();
    107         com.setId(id);
     107        com.setComment("Actual");
     108        com.setProfileDescriptionId(descriptionId);       
    108109        com.setCommentDate(createNewDate());
    109110        return com;
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/model/RegisterResponse.java

    r1633 r1635  
    6464        this.comment = comment;
    6565    }
     66   
     67    public Comment getComment() {
     68        return comment;
     69    }
    6670
    6771    public AbstractDescription getDescription() {
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java

    r1633 r1635  
    657657        return registerComment(input, com, userCredentials, userspace, componentId, new NewAction());
    658658    }
     659   
     660        @POST
     661    @Path("/profiles/{profileId}/comments")
     662    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     663    @Consumes("multipart/form-data")
     664    public Response registerCommentInProfile(@FormDataParam(DATA_FORM_FIELD) InputStream input, @FormDataParam(NAME_FORM_FIELD) String comment,
     665            @FormDataParam("profileId") AbstractDescription profileId, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     666        Principal principal = checkAndGetUserPrincipal();
     667        UserCredentials userCredentials = getUserCredentials(principal);
     668        Comment com = createNewComment();
     669        com.setComponentDescriptionId("profileId");
     670        com.setUserId(userCredentials.getPrincipalName()); // Hash used to be created here, now Id is constructed by impl
     671        com.setComment(comment);
     672        LOG.info("Trying to register Comment: " + com);
     673        return registerComment(input, com, userCredentials, userspace, profileId, new NewAction());
     674    }
    659675
    660676    @GET
     
    717733            RegisterResponse response = new RegisterResponse();
    718734            response.setIsInUserSpace(userspace);
    719             validate(response, validator);
     735            validate(response, commentValidator, validator);
    720736            if (response.getErrors().isEmpty()) {
    721737                Comment spec = validator.getCommentSpec();
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/NewAction.java

    r1633 r1635  
    1616    @Override
    1717    public int executeComment(Comment com, Comment spec, RegisterResponse response, ComponentRegistry registry) {
    18         throw new UnsupportedOperationException("Not supported yet.");
     18        return registry.registerComment(com, spec);
    1919    }
    2020
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/CommentsDaoTest.java

    r1633 r1635  
    4343    @Test
    4444    public void testInsertComment() {
    45         Comment testComment = createTestComment();
     45        Comment comment = createTestComment();
    4646
    4747
    4848
    49         String regDate = Comment.createNewDate();
    5049
    5150        //testComment.setId(TEST_COMMENT_ID);
    52         testComment.setComment("test");
    53         //testComment.setUserID("1");
     51       
     52        //comment.setUserId("1");
    5453        //testComment.setComponentDescriptionId("A component1");
    5554        //testComment.setProfileDescriptionId("A profile1");
    56         testComment.setCommentDate(regDate);
    5755
     56        String testComment = comment.getComment();
    5857        assertEquals(0, commentsDao.getAllComments().size());
    59         Number newId = commentsDao.insertComment(testComment);
     58        Number newId = commentsDao.insertComment(comment, testComment, Integer.parseInt(TEST_COMMENT_USER_ID));
    6059        assertNotNull(newId);
    61 
     60     
    6261        List<Comment> comments = commentsDao.getAllComments();
     62        assertNotNull(comments);
    6363        assertEquals(1, comments.size());
    6464
    6565        assertEquals(TEST_COMMENT_NAME, comments.get(0).getComment());
    6666       // assertEquals("A component1", comments.get(0).getComponentDescriptionId());
    67         //assertEquals("A profile1", comments.get(0).getProfileDescriptionId());
    68         assertEquals(regDate, comments.get(0).getCommentDate());
    69        // assertEquals("1", comments.get(0).getUserId());
    70        // assertEquals(TEST_COMMENT_ID, comments.get(0).getId());
     67        assertEquals(TEST_COMMENT_PROFILE_ID, comments.get(0).getProfileDescriptionId());
     68        assertEquals(TEST_COMMENT_DATE, comments.get(0).getCommentDate());
     69        assertEquals(TEST_COMMENT_USER_ID, comments.get(0).getUserId());
     70        //assertEquals(TEST_COMMENT_ID, comments.get(0).getId());
    7171    }
    7272   
     
    9090    @Test
    9191    public void testGetComment() {
    92         Comment testComment = createTestComment();
    93         commentsDao.insertComment(testComment);
     92        Comment comment = createTestComment();
     93        String testComment = comment.getComment();
     94        commentsDao.insertComment(comment, testComment, 8);
    9495
    9596        assertNotNull(commentsDao.getByComment(TEST_COMMENT_NAME));
     
    109110   
    110111    public void testSetDelete(){
    111         Comment testComment = createTestComment();
     112        Comment comment = createTestComment();
     113        String testComment = comment.getComment();
    112114        int count = commentsDao.getAllComments().size();
    113115       
    114         commentsDao.insertComment(testComment);
     116        commentsDao.insertComment(comment, testComment, 8);
    115117        assertEquals(count + 1, commentsDao.getAllComments().size());
    116118
    117         commentsDao.deleteComment(testComment, true);
     119        commentsDao.deleteComment(comment, true);
    118120        assertEquals(count, commentsDao.getAllComments().size());
    119121       
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java

    r1603 r1635  
    2929import clarin.cmdi.componentregistry.impl.database.ComponentRegistryTestDatabase;
    3030import clarin.cmdi.componentregistry.model.AbstractDescription;
     31import clarin.cmdi.componentregistry.model.Comment;
    3132import clarin.cmdi.componentregistry.model.ComponentDescription;
    3233import clarin.cmdi.componentregistry.model.ProfileDescription;
     
    3839
    3940@RunWith(SpringJUnit4ClassRunner.class)
    40 @ContextConfiguration(locations = { "/applicationContext.xml" })
     41@ContextConfiguration(locations = {"/applicationContext.xml"})
    4142public class ComponentRegistryRestServiceTest extends ComponentRegistryRestServiceTestCase {
    4243
     
    4748    @Autowired
    4849    private JdbcTemplate jdbcTemplate;
    49 
    5050    private ComponentRegistry testRegistry;
    5151
    5252    @Before
    5353    public void init() {
    54         ComponentRegistryTestDatabase.resetAndCreateAllTables(jdbcTemplate);
    55         createUserRecord();
    56         // Get public component registry
    57         testRegistry = componentRegistryBeanFactory.getNewComponentRegistry();
     54        ComponentRegistryTestDatabase.resetAndCreateAllTables(jdbcTemplate);
     55        createUserRecord();
     56        // Get public component registry
     57        testRegistry = componentRegistryBeanFactory.getNewComponentRegistry();
    5858    }
    5959
    6060    @Override
    6161    protected String getApplicationContextFile() {
    62         return "classpath:applicationContext.xml";
     62        return "classpath:applicationContext.xml";
    6363    }
    6464
    6565    private ComponentRegistry getTestRegistry() {
    66         return testRegistry;
     66        return testRegistry;
    6767    }
    6868
    6969    private String expectedUserId(String principal) {
    70         return getUserDao().getByPrincipalName(principal).getId().toString();
     70        return getUserDao().getByPrincipalName(principal).getId().toString();
    7171    }
    7272
    7373    private void fillUp() throws Exception {
    74         RegistryTestHelper.addProfile(getTestRegistry(), "profile2");
    75         RegistryTestHelper.addProfile(getTestRegistry(), "profile1");
    76         RegistryTestHelper.addComponent(getTestRegistry(), "component2");
    77         RegistryTestHelper.addComponent(getTestRegistry(), "component1");
    78     };
     74        RegistryTestHelper.addProfile(getTestRegistry(), "profile2");
     75        RegistryTestHelper.addProfile(getTestRegistry(), "profile1");
     76        RegistryTestHelper.addComponent(getTestRegistry(), "component2");
     77        RegistryTestHelper.addComponent(getTestRegistry(), "component1");
     78        RegistryTestHelper.addComment(getTestRegistry(), "comment2");
     79        RegistryTestHelper.addComment(getTestRegistry(), "comment1");
     80       
     81    }
     82
     83    ;
    7984
    8085    @Test
    8186    public void testGetRegisteredProfiles() throws Exception {
    82         fillUp();
    83         RegistryTestHelper.addProfile(getTestRegistry(), "PROFILE2");
    84         List<ProfileDescription> response = getResource().path("/registry/profiles").accept(MediaType.APPLICATION_XML).get(
    85                 PROFILE_LIST_GENERICTYPE);
    86         assertEquals(3, response.size());
    87         response = getResource().path("/registry/profiles").accept(MediaType.APPLICATION_JSON).get(PROFILE_LIST_GENERICTYPE);
    88         assertEquals(3, response.size());
    89         assertEquals("profile1", response.get(0).getName());
    90         assertEquals("PROFILE2", response.get(1).getName());
    91         assertEquals("profile2", response.get(2).getName());
     87        fillUp();
     88        RegistryTestHelper.addProfile(getTestRegistry(), "PROFILE2");
     89        List<ProfileDescription> response = getResource().path("/registry/profiles").accept(MediaType.APPLICATION_XML).get(
     90                PROFILE_LIST_GENERICTYPE);
     91        assertEquals(3, response.size());
     92        response = getResource().path("/registry/profiles").accept(MediaType.APPLICATION_JSON).get(PROFILE_LIST_GENERICTYPE);
     93        assertEquals(3, response.size());
     94        assertEquals("profile1", response.get(0).getName());
     95        assertEquals("PROFILE2", response.get(1).getName());
     96        assertEquals("profile2", response.get(2).getName());
    9297    }
    9398
    9499    @Test
    95100    public void testGetRegisteredComponents() throws Exception {
    96         fillUp();
    97         RegistryTestHelper.addComponent(getTestRegistry(), "COMPONENT2");
    98         List<ComponentDescription> response = getResource().path("/registry/components").accept(MediaType.APPLICATION_XML).get(
    99                 COMPONENT_LIST_GENERICTYPE);
    100         assertEquals(3, response.size());
    101         response = getResource().path("/registry/components").accept(MediaType.APPLICATION_JSON).get(COMPONENT_LIST_GENERICTYPE);
    102         assertEquals(3, response.size());
    103         assertEquals("component1", response.get(0).getName());
    104         assertEquals("COMPONENT2", response.get(1).getName());
    105         assertEquals("component2", response.get(2).getName());
     101        fillUp();
     102        RegistryTestHelper.addComponent(getTestRegistry(), "COMPONENT2");
     103        List<ComponentDescription> response = getResource().path("/registry/components").accept(MediaType.APPLICATION_XML).get(
     104                COMPONENT_LIST_GENERICTYPE);
     105        assertEquals(3, response.size());
     106        response = getResource().path("/registry/components").accept(MediaType.APPLICATION_JSON).get(COMPONENT_LIST_GENERICTYPE);
     107        assertEquals(3, response.size());
     108        assertEquals("component1", response.get(0).getName());
     109        assertEquals("COMPONENT2", response.get(1).getName());
     110        assertEquals("component2", response.get(2).getName());
    106111    }
    107112
    108113    @Test
    109114    public void testGetUserComponents() throws Exception {
    110         fillUp();
    111         List<ComponentDescription> response = getUserComponents();
    112         assertEquals(0, response.size());
    113         response = getAuthenticatedResource(getResource().path("/registry/components")).accept(MediaType.APPLICATION_JSON).get(
    114                 COMPONENT_LIST_GENERICTYPE);
    115         assertEquals("Get public components", 2, response.size());
    116         ClientResponse cResponse = getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true").accept(
    117                 MediaType.APPLICATION_JSON).get(ClientResponse.class);
    118         assertEquals("Trying to get userspace without credentials", 500, cResponse.getStatus());
     115        fillUp();
     116        List<ComponentDescription> response = getUserComponents();
     117        assertEquals(0, response.size());
     118        response = getAuthenticatedResource(getResource().path("/registry/components")).accept(MediaType.APPLICATION_JSON).get(
     119                COMPONENT_LIST_GENERICTYPE);
     120        assertEquals("Get public components", 2, response.size());
     121        ClientResponse cResponse = getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true").accept(
     122                MediaType.APPLICATION_JSON).get(ClientResponse.class);
     123        assertEquals("Trying to get userspace without credentials", 500, cResponse.getStatus());
    119124    }
    120125
    121126    @Test
    122127    public void testGetRegisteredComponent() throws Exception {
    123         fillUp();
    124         CMDComponentSpec component = getResource().path("/registry/components/clarin.eu:cr1:component1").accept(MediaType.APPLICATION_JSON)
    125                 .get(CMDComponentSpec.class);
    126         assertNotNull(component);
    127         assertEquals("Access", component.getCMDComponent().get(0).getName());
    128         component = getResource().path("/registry/components/clarin.eu:cr1:component2").accept(MediaType.APPLICATION_XML).get(
    129                 CMDComponentSpec.class);
    130         assertNotNull(component);
    131         assertEquals("Access", component.getCMDComponent().get(0).getName());
    132 
    133         assertEquals("clarin.eu:cr1:component2", component.getHeader().getID());
    134         assertEquals("component2", component.getHeader().getName());
    135         assertEquals("Test Description", component.getHeader().getDescription());
     128        fillUp();
     129        CMDComponentSpec component = getResource().path("/registry/components/clarin.eu:cr1:component1").accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class);
     130        assertNotNull(component);
     131        assertEquals("Access", component.getCMDComponent().get(0).getName());
     132        component = getResource().path("/registry/components/clarin.eu:cr1:component2").accept(MediaType.APPLICATION_XML).get(
     133                CMDComponentSpec.class);
     134        assertNotNull(component);
     135        assertEquals("Access", component.getCMDComponent().get(0).getName());
     136
     137        assertEquals("clarin.eu:cr1:component2", component.getHeader().getID());
     138        assertEquals("component2", component.getHeader().getName());
     139        assertEquals("Test Description", component.getHeader().getDescription());
     140    }
     141
     142    @Test
     143    public void testGetRegisteredCommentsInProfile() throws Exception {
     144        fillUp();
     145        RegistryTestHelper.addComment(getTestRegistry(), "COMMENT1");
     146        List<Comment> response = getResource().path("/registry/profiles/clarin.eu:cr1:profile1/comments").accept(MediaType.APPLICATION_XML).
     147                get(COMMENT_LIST_GENERICTYPE);
     148        assertEquals(0, response.size());
     149        response = getResource().path("/registry/components/clarin.eu:cr1:profile1/comments").accept(MediaType.APPLICATION_JSON).get(
     150                COMMENT_LIST_GENERICTYPE);
     151        assertEquals(3, response.size());
     152        assertEquals("comment1", response.get(0).getComment());
     153        assertEquals("comment2", response.get(1).getComment());
     154        assertEquals("COMMENT1", response.get(2).getComment());
    136155    }
    137156
    138157    @Test
    139158    public void testDeleteRegisteredComponent() throws Exception {
    140         fillUp();
    141         List<ComponentDescription> components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE);
    142         assertEquals(2, components.size());
    143         CMDComponentSpec profile = getResource().path("/registry/components/clarin.eu:cr1:component1").get(CMDComponentSpec.class);
    144         assertNotNull(profile);
    145         ClientResponse response = getAuthenticatedResource("/registry/components/clarin.eu:cr1:component1").delete(ClientResponse.class);
    146         assertEquals(200, response.getStatus());
    147 
    148         components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE);
    149         assertEquals(1, components.size());
    150 
    151         response = getAuthenticatedResource("/registry/components/clarin.eu:cr1:component2").delete(ClientResponse.class);
    152         assertEquals(200, response.getStatus());
    153 
    154         components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE);
    155         assertEquals(0, components.size());
    156 
    157         response = getAuthenticatedResource("/registry/components/clarin.eu:cr1:component1").delete(ClientResponse.class);
    158         assertEquals(200, response.getStatus());
     159        fillUp();
     160        List<ComponentDescription> components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE);
     161        assertEquals(2, components.size());
     162        CMDComponentSpec profile = getResource().path("/registry/components/clarin.eu:cr1:component1").get(CMDComponentSpec.class);
     163        assertNotNull(profile);
     164        ClientResponse response = getAuthenticatedResource("/registry/components/clarin.eu:cr1:component1").delete(ClientResponse.class);
     165        assertEquals(200, response.getStatus());
     166
     167        components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE);
     168        assertEquals(1, components.size());
     169
     170        response = getAuthenticatedResource("/registry/components/clarin.eu:cr1:component2").delete(ClientResponse.class);
     171        assertEquals(200, response.getStatus());
     172
     173        components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE);
     174        assertEquals(0, components.size());
     175
     176        response = getAuthenticatedResource("/registry/components/clarin.eu:cr1:component1").delete(ClientResponse.class);
     177        assertEquals(200, response.getStatus());
    159178    }
    160179
    161180    @Test
    162181    public void testDeleteRegisteredComponentStillUsed() throws Exception {
    163         String content = "";
    164         content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    165         content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    166         content += "    <Header/>\n";
    167         content += "    <CMD_Component name=\"XXX\" CardinalityMin=\"1\" CardinalityMax=\"10\">\n";
    168         content += "        <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n";
    169         content += "    </CMD_Component>\n";
    170         content += "</CMD_ComponentSpec>\n";
    171         ComponentDescription compDesc1 = RegistryTestHelper.addComponent(getTestRegistry(), "XXX1", content);
    172 
    173         content = "";
    174         content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    175         content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    176         content += "    <Header/>\n";
    177         content += "    <CMD_Component name=\"YYY\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n";
    178         content += "        <CMD_Component ComponentId=\"" + compDesc1.getId() + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n";
    179         content += "        </CMD_Component>\n";
    180         content += "    </CMD_Component>\n";
    181         content += "</CMD_ComponentSpec>\n";
    182         ComponentDescription compDesc2 = RegistryTestHelper.addComponent(getTestRegistry(), "YYY1", content);
    183 
    184         content = "";
    185         content += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    186         content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    187         content += "    <Header/>\n";
    188         content += "    <CMD_Component name=\"ZZZ\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n";
    189         content += "        <CMD_Component ComponentId=\"" + compDesc1.getId() + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n";
    190         content += "        </CMD_Component>\n";
    191         content += "    </CMD_Component>\n";
    192         content += "</CMD_ComponentSpec>\n";
    193         ProfileDescription profile = RegistryTestHelper.addProfile(getTestRegistry(), "TestProfile3", content);
    194 
    195         List<ComponentDescription> components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE);
    196         assertEquals(2, components.size());
    197 
    198         ClientResponse response = getAuthenticatedResource("/registry/components/" + compDesc1.getId()).delete(ClientResponse.class);
    199         assertEquals(Status.FORBIDDEN.getStatusCode(), response.getStatus());
    200         assertEquals(
    201                 "Still used by the following profiles: \n - TestProfile3\nStill used by the following components: \n - YYY1\nTry to change above mentioned references first.",
    202                 response.getEntity(String.class));
    203 
    204         components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE);
    205         assertEquals(2, components.size());
    206 
    207         response = getAuthenticatedResource("/registry/profiles/" + profile.getId()).delete(ClientResponse.class);
    208         assertEquals(200, response.getStatus());
    209         response = getAuthenticatedResource("/registry/components/" + compDesc2.getId()).delete(ClientResponse.class);
    210         assertEquals(200, response.getStatus());
    211         response = getAuthenticatedResource("/registry/components/" + compDesc1.getId()).delete(ClientResponse.class);
    212         assertEquals(200, response.getStatus());
    213         components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE);
    214         assertEquals(0, components.size());
     182        String content = "";
     183        content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     184        content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     185        content += "    <Header/>\n";
     186        content += "    <CMD_Component name=\"XXX\" CardinalityMin=\"1\" CardinalityMax=\"10\">\n";
     187        content += "        <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n";
     188        content += "    </CMD_Component>\n";
     189        content += "</CMD_ComponentSpec>\n";
     190        ComponentDescription compDesc1 = RegistryTestHelper.addComponent(getTestRegistry(), "XXX1", content);
     191
     192        content = "";
     193        content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     194        content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     195        content += "    <Header/>\n";
     196        content += "    <CMD_Component name=\"YYY\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n";
     197        content += "        <CMD_Component ComponentId=\"" + compDesc1.getId() + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n";
     198        content += "        </CMD_Component>\n";
     199        content += "    </CMD_Component>\n";
     200        content += "</CMD_ComponentSpec>\n";
     201        ComponentDescription compDesc2 = RegistryTestHelper.addComponent(getTestRegistry(), "YYY1", content);
     202
     203        content = "";
     204        content += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     205        content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     206        content += "    <Header/>\n";
     207        content += "    <CMD_Component name=\"ZZZ\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n";
     208        content += "        <CMD_Component ComponentId=\"" + compDesc1.getId() + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n";
     209        content += "        </CMD_Component>\n";
     210        content += "    </CMD_Component>\n";
     211        content += "</CMD_ComponentSpec>\n";
     212        ProfileDescription profile = RegistryTestHelper.addProfile(getTestRegistry(), "TestProfile3", content);
     213
     214        List<ComponentDescription> components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE);
     215        assertEquals(2, components.size());
     216
     217        ClientResponse response = getAuthenticatedResource("/registry/components/" + compDesc1.getId()).delete(ClientResponse.class);
     218        assertEquals(Status.FORBIDDEN.getStatusCode(), response.getStatus());
     219        assertEquals(
     220                "Still used by the following profiles: \n - TestProfile3\nStill used by the following components: \n - YYY1\nTry to change above mentioned references first.",
     221                response.getEntity(String.class));
     222
     223        components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE);
     224        assertEquals(2, components.size());
     225
     226        response = getAuthenticatedResource("/registry/profiles/" + profile.getId()).delete(ClientResponse.class);
     227        assertEquals(200, response.getStatus());
     228        response = getAuthenticatedResource("/registry/components/" + compDesc2.getId()).delete(ClientResponse.class);
     229        assertEquals(200, response.getStatus());
     230        response = getAuthenticatedResource("/registry/components/" + compDesc1.getId()).delete(ClientResponse.class);
     231        assertEquals(200, response.getStatus());
     232        components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE);
     233        assertEquals(0, components.size());
    215234    }
    216235
    217236    @Test
    218237    public void testGetRegisteredProfile() throws Exception {
    219         fillUp();
    220         CMDComponentSpec profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile1").accept(MediaType.APPLICATION_JSON).get(
    221                 CMDComponentSpec.class);
    222         assertNotNull(profile);
    223         assertEquals("Actor", profile.getCMDComponent().get(0).getName());
    224         profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile2").accept(MediaType.APPLICATION_XML).get(
    225                 CMDComponentSpec.class);
    226         assertNotNull(profile);
    227         assertEquals("Actor", profile.getCMDComponent().get(0).getName());
    228 
    229         assertEquals("clarin.eu:cr1:profile2", profile.getHeader().getID());
    230         assertEquals("profile2", profile.getHeader().getName());
    231         assertEquals("Test Description", profile.getHeader().getDescription());
    232 
    233         try {
    234             profile = getResource().path("/registry/profiles/clarin.eu:cr1:profileXXXX").accept(MediaType.APPLICATION_XML).get(
    235                     CMDComponentSpec.class);
    236             fail("Exception should have been thrown resource does not exist, HttpStatusCode 204");
    237         } catch (UniformInterfaceException e) {
    238             assertEquals(204, e.getResponse().getStatus());
    239         }
     238        fillUp();
     239        CMDComponentSpec profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile1").accept(MediaType.APPLICATION_JSON).get(
     240                CMDComponentSpec.class);
     241        assertNotNull(profile);
     242        assertEquals("Actor", profile.getCMDComponent().get(0).getName());
     243        profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile2").accept(MediaType.APPLICATION_XML).get(
     244                CMDComponentSpec.class);
     245        assertNotNull(profile);
     246        assertEquals("Actor", profile.getCMDComponent().get(0).getName());
     247
     248        assertEquals("clarin.eu:cr1:profile2", profile.getHeader().getID());
     249        assertEquals("profile2", profile.getHeader().getName());
     250        assertEquals("Test Description", profile.getHeader().getDescription());
     251
     252        try {
     253            profile = getResource().path("/registry/profiles/clarin.eu:cr1:profileXXXX").accept(MediaType.APPLICATION_XML).get(
     254                    CMDComponentSpec.class);
     255            fail("Exception should have been thrown resource does not exist, HttpStatusCode 204");
     256        } catch (UniformInterfaceException e) {
     257            assertEquals(204, e.getResponse().getStatus());
     258        }
    240259    }
    241260
    242261    @Test
    243262    public void testGetRegisteredProfileRawData() throws Exception {
    244         fillUp();
    245         String profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile1/xsd").accept(MediaType.TEXT_XML).get(String.class);
    246         assertTrue(profile.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema"));
    247         assertTrue(profile.endsWith("</xs:schema>"));
    248 
    249         profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile1/xml").accept(MediaType.TEXT_XML).get(String.class);
    250         assertTrue(profile.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<CMD_ComponentSpec"));
    251         assertTrue(profile.endsWith("</CMD_ComponentSpec>\n"));
    252         assertTrue(profile.contains("xsi:schemaLocation"));
    253 
    254         try {
    255             getResource().path("/registry/components/clarin.eu:cr1:component1/xsl").accept(MediaType.TEXT_XML).get(String.class);
    256             fail("Should have thrown exception, unsupported path parameter");
    257         } catch (UniformInterfaceException e) {//server error
    258         }
     263        fillUp();
     264        String profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile1/xsd").accept(MediaType.TEXT_XML).get(String.class);
     265        assertTrue(profile.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema"));
     266        assertTrue(profile.endsWith("</xs:schema>"));
     267
     268        profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile1/xml").accept(MediaType.TEXT_XML).get(String.class);
     269        assertTrue(profile.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<CMD_ComponentSpec"));
     270        assertTrue(profile.endsWith("</CMD_ComponentSpec>\n"));
     271        assertTrue(profile.contains("xsi:schemaLocation"));
     272
     273        try {
     274            getResource().path("/registry/components/clarin.eu:cr1:component1/xsl").accept(MediaType.TEXT_XML).get(String.class);
     275            fail("Should have thrown exception, unsupported path parameter");
     276        } catch (UniformInterfaceException e) {//server error
     277        }
    259278    }
    260279
    261280    @Test
    262281    public void testPrivateProfileXsd() throws Exception {
    263         FormDataMultiPart form = createFormData(RegistryTestHelper.getTestProfileContent());
    264         RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true"))
    265                 .type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
    266         assertTrue(response.isProfile());
    267         assertEquals(1, getUserProfiles().size());
    268         AbstractDescription desc = response.getDescription();
    269         String profile = getResource().path("/registry/profiles/" + desc.getId() + "/xsd").accept(MediaType.TEXT_XML).get(String.class);
    270         assertTrue(profile.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema"));
    271         assertTrue(profile.endsWith("</xs:schema>"));
     282        FormDataMultiPart form = createFormData(RegistryTestHelper.getTestProfileContent());
     283        RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")).type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
     284        assertTrue(response.isProfile());
     285        assertEquals(1, getUserProfiles().size());
     286        AbstractDescription desc = response.getDescription();
     287        String profile = getResource().path("/registry/profiles/" + desc.getId() + "/xsd").accept(MediaType.TEXT_XML).get(String.class);
     288        assertTrue(profile.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema"));
     289        assertTrue(profile.endsWith("</xs:schema>"));
    272290    }
    273291
    274292    @Test
    275293    public void testPrivateComponentXsd() throws Exception {
    276         FormDataMultiPart form = createFormData(RegistryTestHelper.getComponentTestContent());
    277         RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true"))
    278                 .type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
    279         assertFalse(response.isProfile());
    280         assertEquals(1, getUserComponents().size());
    281         AbstractDescription desc = response.getDescription();
    282         String profile = getResource().path("/registry/components/" + desc.getId() + "/xsd").accept(MediaType.TEXT_XML).get(String.class);
    283         assertTrue(profile.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema"));
    284         assertTrue(profile.endsWith("</xs:schema>"));
     294        FormDataMultiPart form = createFormData(RegistryTestHelper.getComponentTestContent());
     295        RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")).type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
     296        assertFalse(response.isProfile());
     297        assertEquals(1, getUserComponents().size());
     298        AbstractDescription desc = response.getDescription();
     299        String profile = getResource().path("/registry/components/" + desc.getId() + "/xsd").accept(MediaType.TEXT_XML).get(String.class);
     300        assertTrue(profile.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema"));
     301        assertTrue(profile.endsWith("</xs:schema>"));
    285302    }
    286303
    287304    @Test
    288305    public void testDeleteRegisteredProfile() throws Exception {
    289         fillUp();
    290         List<ProfileDescription> profiles = getResource().path("/registry/profiles").get(PROFILE_LIST_GENERICTYPE);
    291         assertEquals(2, profiles.size());
    292         CMDComponentSpec profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile1").get(CMDComponentSpec.class);
    293         assertNotNull(profile);
    294 
    295         ClientResponse response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile1").delete(ClientResponse.class);
    296         assertEquals(200, response.getStatus());
    297 
    298         profiles = getResource().path("/registry/profiles").get(PROFILE_LIST_GENERICTYPE);
    299         assertEquals(1, profiles.size());
    300 
    301         response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile2").delete(ClientResponse.class);
    302         assertEquals(200, response.getStatus());
    303 
    304         profiles = getResource().path("/registry/profiles").get(PROFILE_LIST_GENERICTYPE);
    305         assertEquals(0, profiles.size());
    306 
    307         response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile1").delete(ClientResponse.class);
    308         assertEquals(200, response.getStatus());
     306        fillUp();
     307        List<ProfileDescription> profiles = getResource().path("/registry/profiles").get(PROFILE_LIST_GENERICTYPE);
     308        assertEquals(2, profiles.size());
     309        CMDComponentSpec profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile1").get(CMDComponentSpec.class);
     310        assertNotNull(profile);
     311
     312        ClientResponse response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile1").delete(ClientResponse.class);
     313        assertEquals(200, response.getStatus());
     314
     315        profiles = getResource().path("/registry/profiles").get(PROFILE_LIST_GENERICTYPE);
     316        assertEquals(1, profiles.size());
     317
     318        response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile2").delete(ClientResponse.class);
     319        assertEquals(200, response.getStatus());
     320
     321        profiles = getResource().path("/registry/profiles").get(PROFILE_LIST_GENERICTYPE);
     322        assertEquals(0, profiles.size());
     323
     324        response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile1").delete(ClientResponse.class);
     325        assertEquals(200, response.getStatus());
    309326    }
    310327
    311328    @Test
    312329    public void testGetRegisteredComponentRawData() throws Exception {
    313         fillUp();
    314         String component = getResource().path("/registry/components/clarin.eu:cr1:component1/xsd").accept(MediaType.TEXT_XML).get(
    315                 String.class);
    316         assertTrue(component.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema"));
    317         assertTrue(component.endsWith("</xs:schema>"));
    318 
    319         component = getResource().path("/registry/components/clarin.eu:cr1:component1/xml").accept(MediaType.TEXT_XML).get(String.class);
    320         assertTrue(component.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<CMD_ComponentSpec"));
    321         assertTrue(component.endsWith("</CMD_ComponentSpec>\n"));
    322         assertTrue(component.contains("xsi:schemaLocation"));
    323 
    324         try {
    325             getResource().path("/registry/components/clarin.eu:cr1:component1/jpg").accept(MediaType.TEXT_XML).get(String.class);
    326             fail("Should have thrown exception, unsopported path parameter");
    327         } catch (UniformInterfaceException e) {
    328         }
     330        fillUp();
     331        String component = getResource().path("/registry/components/clarin.eu:cr1:component1/xsd").accept(MediaType.TEXT_XML).get(
     332                String.class);
     333        assertTrue(component.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema"));
     334        assertTrue(component.endsWith("</xs:schema>"));
     335
     336        component = getResource().path("/registry/components/clarin.eu:cr1:component1/xml").accept(MediaType.TEXT_XML).get(String.class);
     337        assertTrue(component.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<CMD_ComponentSpec"));
     338        assertTrue(component.endsWith("</CMD_ComponentSpec>\n"));
     339        assertTrue(component.contains("xsi:schemaLocation"));
     340
     341        try {
     342            getResource().path("/registry/components/clarin.eu:cr1:component1/jpg").accept(MediaType.TEXT_XML).get(String.class);
     343            fail("Should have thrown exception, unsopported path parameter");
     344        } catch (UniformInterfaceException e) {
     345        }
    329346    }
    330347
    331348    @Test
    332349    public void testRegisterProfile() throws Exception {
    333         FormDataMultiPart form = new FormDataMultiPart();
    334         form.field(ComponentRegistryRestService.DATA_FORM_FIELD, RegistryTestHelper.getTestProfileContent(),
    335                 MediaType.APPLICATION_OCTET_STREAM_TYPE);
    336         form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "ProfileTest1");
    337         form.field(ComponentRegistryRestService.DOMAIN_FORM_FIELD, "TestDomain");
    338         form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test Profile");
    339         form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, "My Test Group");
    340         RegisterResponse response = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
    341                 RegisterResponse.class, form);
    342         assertTrue(response.isProfile());
    343         assertFalse(response.isInUserSpace());
    344         ProfileDescription profileDesc = (ProfileDescription) response.getDescription();
    345         assertNotNull(profileDesc);
    346         assertEquals("ProfileTest1", profileDesc.getName());
    347         assertEquals("My Test Profile", profileDesc.getDescription());
    348         assertEquals("TestDomain", profileDesc.getDomainName());
    349         assertEquals("My Test Group", profileDesc.getGroupName());
    350         assertEquals(expectedUserId("JUnit@test.com"), profileDesc.getUserId());
    351         assertEquals("JUnit@test.com", profileDesc.getCreatorName());
    352         assertTrue(profileDesc.getId().startsWith(ComponentRegistry.REGISTRY_ID + "p_"));
    353         assertNotNull(profileDesc.getRegistrationDate());
    354         assertEquals("http://localhost:9998/registry/profiles/" + profileDesc.getId(), profileDesc.getHref());
     350        FormDataMultiPart form = new FormDataMultiPart();
     351        form.field(ComponentRegistryRestService.DATA_FORM_FIELD, RegistryTestHelper.getTestProfileContent(),
     352                MediaType.APPLICATION_OCTET_STREAM_TYPE);
     353        form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "ProfileTest1");
     354        form.field(ComponentRegistryRestService.DOMAIN_FORM_FIELD, "TestDomain");
     355        form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test Profile");
     356        form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, "My Test Group");
     357        RegisterResponse response = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
     358                RegisterResponse.class, form);
     359        assertTrue(response.isProfile());
     360        assertFalse(response.isInUserSpace());
     361        ProfileDescription profileDesc = (ProfileDescription) response.getDescription();
     362        assertNotNull(profileDesc);
     363        assertEquals("ProfileTest1", profileDesc.getName());
     364        assertEquals("My Test Profile", profileDesc.getDescription());
     365        assertEquals("TestDomain", profileDesc.getDomainName());
     366        assertEquals("My Test Group", profileDesc.getGroupName());
     367        assertEquals(expectedUserId("JUnit@test.com"), profileDesc.getUserId());
     368        assertEquals("JUnit@test.com", profileDesc.getCreatorName());
     369        assertTrue(profileDesc.getId().startsWith(ComponentRegistry.REGISTRY_ID + "p_"));
     370        assertNotNull(profileDesc.getRegistrationDate());
     371        assertEquals("http://localhost:9998/registry/profiles/" + profileDesc.getId(), profileDesc.getHref());
    355372    }
    356373
    357374    @Test
    358375    public void testPublishProfile() throws Exception {
    359         assertEquals("user registered profiles", 0, getUserProfiles().size());
    360         assertEquals("public registered profiles", 0, getPublicProfiles().size());
    361         FormDataMultiPart form = createFormData(RegistryTestHelper.getTestProfileContent(), "Unpublished");
    362         RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true"))
    363                 .type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
    364         assertTrue(response.isProfile());
    365         AbstractDescription desc = response.getDescription();
    366         assertEquals("Unpublished", desc.getDescription());
    367         assertEquals(1, getUserProfiles().size());
    368         assertEquals(0, getPublicProfiles().size());
    369         form = createFormData(RegistryTestHelper.getTestProfileContent("publishedName"), "Published");
    370         response = getAuthenticatedResource(getResource().path("/registry/profiles/" + desc.getId() + "/publish")).type(
    371                 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
    372 
    373         assertEquals(0, getUserProfiles().size());
    374         List<ProfileDescription> profiles = getPublicProfiles();
    375         assertEquals(1, profiles.size());
    376         ProfileDescription profileDescription = profiles.get(0);
    377         assertNotNull(profileDescription.getId());
    378         assertEquals(desc.getId(), profileDescription.getId());
    379         assertEquals("http://localhost:9998/registry/profiles/" + desc.getId(), profileDescription.getHref());
    380         assertEquals("Published", profileDescription.getDescription());
    381         CMDComponentSpec spec = getPublicSpec(profileDescription);
    382         assertEquals("publishedName", spec.getCMDComponent().get(0).getName());
     376        assertEquals("user registered profiles", 0, getUserProfiles().size());
     377        assertEquals("public registered profiles", 0, getPublicProfiles().size());
     378        FormDataMultiPart form = createFormData(RegistryTestHelper.getTestProfileContent(), "Unpublished");
     379        RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")).type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
     380        assertTrue(response.isProfile());
     381        AbstractDescription desc = response.getDescription();
     382        assertEquals("Unpublished", desc.getDescription());
     383        assertEquals(1, getUserProfiles().size());
     384        assertEquals(0, getPublicProfiles().size());
     385        form = createFormData(RegistryTestHelper.getTestProfileContent("publishedName"), "Published");
     386        response = getAuthenticatedResource(getResource().path("/registry/profiles/" + desc.getId() + "/publish")).type(
     387                MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
     388
     389        assertEquals(0, getUserProfiles().size());
     390        List<ProfileDescription> profiles = getPublicProfiles();
     391        assertEquals(1, profiles.size());
     392        ProfileDescription profileDescription = profiles.get(0);
     393        assertNotNull(profileDescription.getId());
     394        assertEquals(desc.getId(), profileDescription.getId());
     395        assertEquals("http://localhost:9998/registry/profiles/" + desc.getId(), profileDescription.getHref());
     396        assertEquals("Published", profileDescription.getDescription());
     397        CMDComponentSpec spec = getPublicSpec(profileDescription);
     398        assertEquals("publishedName", spec.getCMDComponent().get(0).getName());
    383399    }
    384400
    385401    private CMDComponentSpec getPublicSpec(AbstractDescription desc) {
    386         if (desc.isProfile()) {
    387             return getResource().path("/registry/profiles/" + desc.getId()).get(CMDComponentSpec.class);
    388         } else {
    389             return getResource().path("/registry/components/" + desc.getId()).get(CMDComponentSpec.class);
    390         }
     402        if (desc.isProfile()) {
     403            return getResource().path("/registry/profiles/" + desc.getId()).get(CMDComponentSpec.class);
     404        } else {
     405            return getResource().path("/registry/components/" + desc.getId()).get(CMDComponentSpec.class);
     406        }
    391407    }
    392408
    393409    @Test
    394410    public void testPublishComponent() throws Exception {
    395         assertEquals(0, getUserComponents().size());
    396         assertEquals(0, getPublicComponents().size());
    397         FormDataMultiPart form = createFormData(RegistryTestHelper.getComponentTestContent(), "Unpublished");
    398         RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true"))
    399                 .type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
    400         assertFalse(response.isProfile());
    401         AbstractDescription desc = response.getDescription();
    402         assertEquals("Unpublished", desc.getDescription());
    403         assertEquals(1, getUserComponents().size());
    404         assertEquals(0, getPublicComponents().size());
    405         form = createFormData(RegistryTestHelper.getComponentTestContent("publishedName"), "Published");
    406         response = getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId() + "/publish")).type(
    407                 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
    408 
    409         assertEquals(0, getUserComponents().size());
    410         List<ComponentDescription> components = getPublicComponents();
    411         assertEquals(1, components.size());
    412         ComponentDescription componentDescription = components.get(0);
    413         assertNotNull(componentDescription.getId());
    414         assertEquals(desc.getId(), componentDescription.getId());
    415         assertEquals("http://localhost:9998/registry/components/" + desc.getId(), componentDescription.getHref());
    416         assertEquals("Published", componentDescription.getDescription());
    417         CMDComponentSpec spec = getPublicSpec(componentDescription);
    418         assertEquals("publishedName", spec.getCMDComponent().get(0).getName());
     411        assertEquals(0, getUserComponents().size());
     412        assertEquals(0, getPublicComponents().size());
     413        FormDataMultiPart form = createFormData(RegistryTestHelper.getComponentTestContent(), "Unpublished");
     414        RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")).type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
     415        assertFalse(response.isProfile());
     416        AbstractDescription desc = response.getDescription();
     417        assertEquals("Unpublished", desc.getDescription());
     418        assertEquals(1, getUserComponents().size());
     419        assertEquals(0, getPublicComponents().size());
     420        form = createFormData(RegistryTestHelper.getComponentTestContent("publishedName"), "Published");
     421        response = getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId() + "/publish")).type(
     422                MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
     423
     424        assertEquals(0, getUserComponents().size());
     425        List<ComponentDescription> components = getPublicComponents();
     426        assertEquals(1, components.size());
     427        ComponentDescription componentDescription = components.get(0);
     428        assertNotNull(componentDescription.getId());
     429        assertEquals(desc.getId(), componentDescription.getId());
     430        assertEquals("http://localhost:9998/registry/components/" + desc.getId(), componentDescription.getHref());
     431        assertEquals("Published", componentDescription.getDescription());
     432        CMDComponentSpec spec = getPublicSpec(componentDescription);
     433        assertEquals("publishedName", spec.getCMDComponent().get(0).getName());
    419434    }
    420435
    421436    @Test
    422437    public void testRegisterUserspaceProfile() throws Exception {
    423         List<ProfileDescription> profiles = getUserProfiles();
    424         assertEquals("user registered profiles", 0, profiles.size());
    425         assertEquals("public registered profiles", 0, getPublicProfiles().size());
    426         FormDataMultiPart form = createFormData(RegistryTestHelper.getTestProfileContent());
    427         RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true"))
    428                 .type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
    429         assertTrue(response.isProfile());
    430         assertTrue(response.isInUserSpace());
    431         ProfileDescription profileDesc = (ProfileDescription) response.getDescription();
    432         assertNotNull(profileDesc);
    433         assertEquals("Test1", profileDesc.getName());
    434         assertEquals("My Test", profileDesc.getDescription());
    435         assertEquals(expectedUserId("JUnit@test.com"), profileDesc.getUserId());
    436         assertEquals("JUnit@test.com", profileDesc.getCreatorName());
    437         assertTrue(profileDesc.getId().startsWith(ComponentRegistry.REGISTRY_ID + "p_"));
    438         assertNotNull(profileDesc.getRegistrationDate());
    439         assertEquals("http://localhost:9998/registry/profiles/" + profileDesc.getId() + "?userspace=true", profileDesc.getHref());
    440 
    441         profiles = getUserProfiles();
    442         assertEquals(1, profiles.size());
    443         assertEquals(0, getPublicProfiles().size());
    444         // Try get from public registry
    445         ClientResponse cResponse = getResource().path("/registry/profiles/" + profileDesc.getId()).accept(MediaType.APPLICATION_XML).get(
    446                 ClientResponse.class);
    447         // Should return 204 = no content
    448         assertEquals(204, cResponse.getStatus());
    449         CMDComponentSpec spec = getAuthenticatedResource(
    450                 getResource().path("/registry/profiles/" + profileDesc.getId()).queryParam(USERSPACE_PARAM, "true")).accept(
    451                 MediaType.APPLICATION_XML).get(CMDComponentSpec.class);
    452         assertNotNull(spec);
    453 
    454         cResponse = getResource().path("/registry/profiles/" + profileDesc.getId() + "/xsd").accept(MediaType.TEXT_XML).get(
    455                 ClientResponse.class);
    456         assertEquals(200, cResponse.getStatus());
    457         String profile = cResponse.getEntity(String.class);
    458         assertTrue(profile.length() > 0);
    459 
    460         profile = getAuthenticatedResource(getResource().path("/registry/profiles/" + profileDesc.getId() + "/xml")).accept(
    461                 MediaType.TEXT_XML).get(String.class);
    462         assertTrue(profile.length() > 0);
    463 
    464         cResponse = getAuthenticatedResource(
    465                 getResource().path("/registry/profiles/" + profileDesc.getId()).queryParam(USERSPACE_PARAM, "true")).delete(
    466                 ClientResponse.class);
    467         assertEquals(200, cResponse.getStatus());
    468 
    469         profiles = getUserProfiles();
    470         assertEquals(0, profiles.size());
     438        List<ProfileDescription> profiles = getUserProfiles();
     439        assertEquals("user registered profiles", 0, profiles.size());
     440        assertEquals("public registered profiles", 0, getPublicProfiles().size());
     441        FormDataMultiPart form = createFormData(RegistryTestHelper.getTestProfileContent());
     442        RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")).type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
     443        assertTrue(response.isProfile());
     444        assertTrue(response.isInUserSpace());
     445        ProfileDescription profileDesc = (ProfileDescription) response.getDescription();
     446        assertNotNull(profileDesc);
     447        assertEquals("Test1", profileDesc.getName());
     448        assertEquals("My Test", profileDesc.getDescription());
     449        assertEquals(expectedUserId("JUnit@test.com"), profileDesc.getUserId());
     450        assertEquals("JUnit@test.com", profileDesc.getCreatorName());
     451        assertTrue(profileDesc.getId().startsWith(ComponentRegistry.REGISTRY_ID + "p_"));
     452        assertNotNull(profileDesc.getRegistrationDate());
     453        assertEquals("http://localhost:9998/registry/profiles/" + profileDesc.getId() + "?userspace=true", profileDesc.getHref());
     454
     455        profiles = getUserProfiles();
     456        assertEquals(1, profiles.size());
     457        assertEquals(0, getPublicProfiles().size());
     458        // Try get from public registry
     459        ClientResponse cResponse = getResource().path("/registry/profiles/" + profileDesc.getId()).accept(MediaType.APPLICATION_XML).get(
     460                ClientResponse.class);
     461        // Should return 204 = no content
     462        assertEquals(204, cResponse.getStatus());
     463        CMDComponentSpec spec = getAuthenticatedResource(
     464                getResource().path("/registry/profiles/" + profileDesc.getId()).queryParam(USERSPACE_PARAM, "true")).accept(
     465                MediaType.APPLICATION_XML).get(CMDComponentSpec.class);
     466        assertNotNull(spec);
     467
     468        cResponse = getResource().path("/registry/profiles/" + profileDesc.getId() + "/xsd").accept(MediaType.TEXT_XML).get(
     469                ClientResponse.class);
     470        assertEquals(200, cResponse.getStatus());
     471        String profile = cResponse.getEntity(String.class);
     472        assertTrue(profile.length() > 0);
     473
     474        profile = getAuthenticatedResource(getResource().path("/registry/profiles/" + profileDesc.getId() + "/xml")).accept(
     475                MediaType.TEXT_XML).get(String.class);
     476        assertTrue(profile.length() > 0);
     477
     478        cResponse = getAuthenticatedResource(
     479                getResource().path("/registry/profiles/" + profileDesc.getId()).queryParam(USERSPACE_PARAM, "true")).delete(
     480                ClientResponse.class);
     481        assertEquals(200, cResponse.getStatus());
     482
     483        profiles = getUserProfiles();
     484        assertEquals(0, profiles.size());
    471485    }
    472486
    473487    private List<ProfileDescription> getPublicProfiles() {
    474         return getAuthenticatedResource("/registry/profiles").accept(MediaType.APPLICATION_XML).get(PROFILE_LIST_GENERICTYPE);
     488        return getAuthenticatedResource("/registry/profiles").accept(MediaType.APPLICATION_XML).get(PROFILE_LIST_GENERICTYPE);
    475489    }
    476490
    477491    private List<ProfileDescription> getUserProfiles() {
    478         return getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")).accept(
    479                 MediaType.APPLICATION_XML).get(PROFILE_LIST_GENERICTYPE);
     492        return getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")).accept(
     493                MediaType.APPLICATION_XML).get(PROFILE_LIST_GENERICTYPE);
    480494    }
    481495
    482496    private FormDataMultiPart createFormData(Object content) {
    483         return createFormData(content, "My Test");
     497        return createFormData(content, "My Test");
    484498    }
    485499
    486500    private FormDataMultiPart createFormData(Object content, String description) {
    487         FormDataMultiPart form = new FormDataMultiPart();
    488         form.field(ComponentRegistryRestService.DATA_FORM_FIELD, content, MediaType.APPLICATION_OCTET_STREAM_TYPE);
    489         form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "Test1");
    490         form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, description);
    491         form.field(ComponentRegistryRestService.DOMAIN_FORM_FIELD, "My domain");
    492         form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup");
    493         return form;
     501        FormDataMultiPart form = new FormDataMultiPart();
     502        form.field(ComponentRegistryRestService.DATA_FORM_FIELD, content, MediaType.APPLICATION_OCTET_STREAM_TYPE);
     503        form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "Test1");
     504        form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, description);
     505        form.field(ComponentRegistryRestService.DOMAIN_FORM_FIELD, "My domain");
     506        form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup");
     507        return form;
    494508    }
    495509
    496510    @Test
    497511    public void testRegisterWithUserComponents() throws Exception {
    498         ComponentRegistry userRegistry = componentRegistryFactory.getComponentRegistry(true, DummyPrincipal.DUMMY_CREDENTIALS);
    499         String content = "";
    500         content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    501         content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    502         content += "    <Header/>\n";
    503         content += "    <CMD_Component name=\"XXX\" CardinalityMin=\"1\" CardinalityMax=\"10\">\n";
    504         content += "        <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n";
    505         content += "    </CMD_Component>\n";
    506         content += "</CMD_ComponentSpec>\n";
    507         ComponentDescription compDesc1 = RegistryTestHelper.addComponent(userRegistry, "XXX1", content);
    508 
    509         content = "";
    510         content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    511         content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    512         content += "    <Header/>\n";
    513         content += "    <CMD_Component name=\"YYY\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n";
    514         content += "        <CMD_Component ComponentId=\"" + compDesc1.getId() + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n";
    515         content += "        </CMD_Component>\n";
    516         content += "    </CMD_Component>\n";
    517         content += "</CMD_ComponentSpec>\n";
    518         FormDataMultiPart form = createFormData(content);
    519         RegisterResponse response = getAuthenticatedResource("/registry/components").type(MediaType.MULTIPART_FORM_DATA).post(
    520                 RegisterResponse.class, form);
    521         assertFalse(response.isRegistered());
    522         assertEquals(1, response.getErrors().size());
    523         assertEquals("referenced component cannot be found in the published components: " + compDesc1.getName() + " (" + compDesc1.getId()
    524                 + ")", response.getErrors().get(0));
    525 
    526         response = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")).type(
    527                 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
    528         assertTrue(response.isRegistered());
    529         ComponentDescription comp2 = (ComponentDescription) response.getDescription();
    530 
    531         content = "";
    532         content += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    533         content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    534         content += "    <Header/>\n";
    535         content += "    <CMD_Component name=\"ZZZ\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n";
    536         content += "        <CMD_Component ComponentId=\"" + comp2.getId() + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n";
    537         content += "        </CMD_Component>\n";
    538         content += "    </CMD_Component>\n";
    539         content += "</CMD_ComponentSpec>\n";
    540 
    541         form = createFormData(content);
    542         response = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
    543         assertFalse(response.isRegistered());
    544         assertEquals(1, response.getErrors().size());
    545         assertEquals("referenced component cannot be found in the published components: " + comp2.getName() + " (" + comp2.getId() + ")",
    546                 response.getErrors().get(0));
    547 
    548         response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")).type(
    549                 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
    550         assertTrue(response.isRegistered());
     512        ComponentRegistry userRegistry = componentRegistryFactory.getComponentRegistry(true, DummyPrincipal.DUMMY_CREDENTIALS);
     513        String content = "";
     514        content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     515        content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     516        content += "    <Header/>\n";
     517        content += "    <CMD_Component name=\"XXX\" CardinalityMin=\"1\" CardinalityMax=\"10\">\n";
     518        content += "        <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n";
     519        content += "    </CMD_Component>\n";
     520        content += "</CMD_ComponentSpec>\n";
     521        ComponentDescription compDesc1 = RegistryTestHelper.addComponent(userRegistry, "XXX1", content);
     522
     523        content = "";
     524        content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     525        content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     526        content += "    <Header/>\n";
     527        content += "    <CMD_Component name=\"YYY\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n";
     528        content += "        <CMD_Component ComponentId=\"" + compDesc1.getId() + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n";
     529        content += "        </CMD_Component>\n";
     530        content += "    </CMD_Component>\n";
     531        content += "</CMD_ComponentSpec>\n";
     532        FormDataMultiPart form = createFormData(content);
     533        RegisterResponse response = getAuthenticatedResource("/registry/components").type(MediaType.MULTIPART_FORM_DATA).post(
     534                RegisterResponse.class, form);
     535        assertFalse(response.isRegistered());
     536        assertEquals(1, response.getErrors().size());
     537        assertEquals("referenced component cannot be found in the published components: " + compDesc1.getName() + " (" + compDesc1.getId()
     538                + ")", response.getErrors().get(0));
     539
     540        response = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")).type(
     541                MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
     542        assertTrue(response.isRegistered());
     543        ComponentDescription comp2 = (ComponentDescription) response.getDescription();
     544
     545        content = "";
     546        content += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     547        content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     548        content += "    <Header/>\n";
     549        content += "    <CMD_Component name=\"ZZZ\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n";
     550        content += "        <CMD_Component ComponentId=\"" + comp2.getId() + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n";
     551        content += "        </CMD_Component>\n";
     552        content += "    </CMD_Component>\n";
     553        content += "</CMD_ComponentSpec>\n";
     554
     555        form = createFormData(content);
     556        response = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
     557        assertFalse(response.isRegistered());
     558        assertEquals(1, response.getErrors().size());
     559        assertEquals("referenced component cannot be found in the published components: " + comp2.getName() + " (" + comp2.getId() + ")",
     560                response.getErrors().get(0));
     561
     562        response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")).type(
     563                MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
     564        assertTrue(response.isRegistered());
    551565    }
    552566
    553567    @Test
    554568    public void testRegisterUserspaceComponent() throws Exception {
    555         List<ComponentDescription> components = getUserComponents();
    556         assertEquals("user registered components", 0, components.size());
    557         assertEquals("public registered components", 0, getPublicComponents().size());
    558         FormDataMultiPart form = createFormData(RegistryTestHelper.getComponentTestContent());
    559 
    560         RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true"))
    561                 .type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
    562         assertTrue(response.isRegistered());
    563         assertFalse(response.isProfile());
    564         assertTrue(response.isInUserSpace());
    565         ComponentDescription desc = (ComponentDescription) response.getDescription();
    566         assertNotNull(desc);
    567         assertEquals("Test1", desc.getName());
    568         assertEquals("My Test", desc.getDescription());
    569         assertEquals(expectedUserId("JUnit@test.com"), desc.getUserId());
    570         assertEquals("JUnit@test.com", desc.getCreatorName());
    571         assertEquals("TestGroup", desc.getGroupName());
    572         assertTrue(desc.getId().startsWith(ComponentRegistry.REGISTRY_ID + "c_"));
    573         assertNotNull(desc.getRegistrationDate());
    574         String url = getResource().getUriBuilder().build().toString();
    575         assertEquals(url + "registry/components/" + desc.getId() + "?userspace=true", desc.getHref());
    576 
    577         components = getUserComponents();
    578         assertEquals(1, components.size());
    579         assertEquals(0, getPublicComponents().size());
    580 
    581         // Try to get from public registry
    582         ClientResponse cResponse = getResource().path("/registry/components/" + desc.getId()).accept(MediaType.APPLICATION_XML).get(
    583                 ClientResponse.class);
    584         // Should return 204 = no content
    585         assertEquals(204, cResponse.getStatus());
    586         CMDComponentSpec spec = getUserComponent(desc);
    587         assertNotNull(spec);
    588 
    589         cResponse = getResource().path("/registry/components/" + desc.getId() + "/xsd").accept(MediaType.TEXT_XML)
    590                 .get(ClientResponse.class);
    591         assertEquals(200, cResponse.getStatus());
    592         String result = cResponse.getEntity(String.class);
    593         assertTrue(result.length() > 0);
    594 
    595         result = getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId() + "/xml")).accept(MediaType.TEXT_XML)
    596                 .get(String.class);
    597         assertTrue(result.length() > 0);
    598 
    599         cResponse = getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId()).queryParam(USERSPACE_PARAM, "true"))
    600                 .delete(ClientResponse.class);
    601         assertEquals(200, cResponse.getStatus());
    602 
    603         components = getUserComponents();
    604         assertEquals(0, components.size());
     569        List<ComponentDescription> components = getUserComponents();
     570        assertEquals("user registered components", 0, components.size());
     571        assertEquals("public registered components", 0, getPublicComponents().size());
     572        FormDataMultiPart form = createFormData(RegistryTestHelper.getComponentTestContent());
     573
     574        RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")).type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
     575        assertTrue(response.isRegistered());
     576        assertFalse(response.isProfile());
     577        assertTrue(response.isInUserSpace());
     578        ComponentDescription desc = (ComponentDescription) response.getDescription();
     579        assertNotNull(desc);
     580        assertEquals("Test1", desc.getName());
     581        assertEquals("My Test", desc.getDescription());
     582        assertEquals(expectedUserId("JUnit@test.com"), desc.getUserId());
     583        assertEquals("JUnit@test.com", desc.getCreatorName());
     584        assertEquals("TestGroup", desc.getGroupName());
     585        assertTrue(desc.getId().startsWith(ComponentRegistry.REGISTRY_ID + "c_"));
     586        assertNotNull(desc.getRegistrationDate());
     587        String url = getResource().getUriBuilder().build().toString();
     588        assertEquals(url + "registry/components/" + desc.getId() + "?userspace=true", desc.getHref());
     589
     590        components = getUserComponents();
     591        assertEquals(1, components.size());
     592        assertEquals(0, getPublicComponents().size());
     593
     594        // Try to get from public registry
     595        ClientResponse cResponse = getResource().path("/registry/components/" + desc.getId()).accept(MediaType.APPLICATION_XML).get(
     596                ClientResponse.class);
     597        // Should return 204 = no content
     598        assertEquals(204, cResponse.getStatus());
     599        CMDComponentSpec spec = getUserComponent(desc);
     600        assertNotNull(spec);
     601
     602        cResponse = getResource().path("/registry/components/" + desc.getId() + "/xsd").accept(MediaType.TEXT_XML).get(ClientResponse.class);
     603        assertEquals(200, cResponse.getStatus());
     604        String result = cResponse.getEntity(String.class);
     605        assertTrue(result.length() > 0);
     606
     607        result = getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId() + "/xml")).accept(MediaType.TEXT_XML).get(String.class);
     608        assertTrue(result.length() > 0);
     609
     610        cResponse = getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId()).queryParam(USERSPACE_PARAM, "true")).delete(ClientResponse.class);
     611        assertEquals(200, cResponse.getStatus());
     612
     613        components = getUserComponents();
     614        assertEquals(0, components.size());
    605615    }
    606616
    607617    @Test
    608618    public void testUpdateComponent() throws Exception {
    609         List<ComponentDescription> components = getUserComponents();
    610         assertEquals("user registered components", 0, components.size());
    611         assertEquals("public registered components", 0, getPublicComponents().size());
    612 
    613         FormDataMultiPart form = createFormData(RegistryTestHelper.getComponentTestContent());
    614         ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true"))
    615                 .type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
    616         assertEquals(ClientResponse.Status.OK.getStatusCode(), cResponse.getStatus());
    617         RegisterResponse response = cResponse.getEntity(RegisterResponse.class);
    618         assertTrue(response.isRegistered());
    619         assertFalse(response.isProfile());
    620         assertTrue(response.isInUserSpace());
    621         ComponentDescription desc = (ComponentDescription) response.getDescription();
    622         assertNotNull(desc);
    623         assertEquals("Test1", desc.getName());
    624         assertEquals("My Test", desc.getDescription());
    625         Date firstDate = AbstractDescription.getDate(desc.getRegistrationDate());
    626         CMDComponentSpec spec = getUserComponent(desc);
    627         assertNotNull(spec);
    628         assertEquals("Access", spec.getCMDComponent().get(0).getName());
    629         components = getUserComponents();
    630         assertEquals(1, components.size());
    631         assertEquals(0, getPublicComponents().size());
    632 
    633         //Now update
    634         form = createFormData(RegistryTestHelper.getComponentTestContent("TESTNAME"), "UPDATE DESCRIPTION!");
    635         cResponse = getAuthenticatedResource(
    636                 getResource().path("/registry/components/" + desc.getId() + "/update").queryParam(USERSPACE_PARAM, "true")).type(
    637                 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
    638         assertEquals(ClientResponse.Status.OK.getStatusCode(), cResponse.getStatus());
    639         response = cResponse.getEntity(RegisterResponse.class);
    640         assertTrue(response.isRegistered());
    641         assertFalse(response.isProfile());
    642         assertTrue(response.isInUserSpace());
    643         desc = (ComponentDescription) response.getDescription();
    644         assertNotNull(desc);
    645         assertEquals("Test1", desc.getName());
    646         assertEquals("UPDATE DESCRIPTION!", desc.getDescription());
    647         Date secondDate = AbstractDescription.getDate(desc.getRegistrationDate());
    648         assertTrue(firstDate.before(secondDate) || firstDate.equals(secondDate));
    649 
    650         spec = getUserComponent(desc);
    651         assertNotNull(spec);
    652         assertEquals("TESTNAME", spec.getCMDComponent().get(0).getName());
    653         components = getUserComponents();
    654         assertEquals(1, components.size());
    655         assertEquals(0, getPublicComponents().size());
     619        List<ComponentDescription> components = getUserComponents();
     620        assertEquals("user registered components", 0, components.size());
     621        assertEquals("public registered components", 0, getPublicComponents().size());
     622
     623        FormDataMultiPart form = createFormData(RegistryTestHelper.getComponentTestContent());
     624        ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")).type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
     625        assertEquals(ClientResponse.Status.OK.getStatusCode(), cResponse.getStatus());
     626        RegisterResponse response = cResponse.getEntity(RegisterResponse.class);
     627        assertTrue(response.isRegistered());
     628        assertFalse(response.isProfile());
     629        assertTrue(response.isInUserSpace());
     630        ComponentDescription desc = (ComponentDescription) response.getDescription();
     631        assertNotNull(desc);
     632        assertEquals("Test1", desc.getName());
     633        assertEquals("My Test", desc.getDescription());
     634        Date firstDate = AbstractDescription.getDate(desc.getRegistrationDate());
     635        CMDComponentSpec spec = getUserComponent(desc);
     636        assertNotNull(spec);
     637        assertEquals("Access", spec.getCMDComponent().get(0).getName());
     638        components = getUserComponents();
     639        assertEquals(1, components.size());
     640        assertEquals(0, getPublicComponents().size());
     641
     642        //Now update
     643        form = createFormData(RegistryTestHelper.getComponentTestContent("TESTNAME"), "UPDATE DESCRIPTION!");
     644        cResponse = getAuthenticatedResource(
     645                getResource().path("/registry/components/" + desc.getId() + "/update").queryParam(USERSPACE_PARAM, "true")).type(
     646                MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
     647        assertEquals(ClientResponse.Status.OK.getStatusCode(), cResponse.getStatus());
     648        response = cResponse.getEntity(RegisterResponse.class);
     649        assertTrue(response.isRegistered());
     650        assertFalse(response.isProfile());
     651        assertTrue(response.isInUserSpace());
     652        desc = (ComponentDescription) response.getDescription();
     653        assertNotNull(desc);
     654        assertEquals("Test1", desc.getName());
     655        assertEquals("UPDATE DESCRIPTION!", desc.getDescription());
     656        Date secondDate = AbstractDescription.getDate(desc.getRegistrationDate());
     657        assertTrue(firstDate.before(secondDate) || firstDate.equals(secondDate));
     658
     659        spec = getUserComponent(desc);
     660        assertNotNull(spec);
     661        assertEquals("TESTNAME", spec.getCMDComponent().get(0).getName());
     662        components = getUserComponents();
     663        assertEquals(1, components.size());
     664        assertEquals(0, getPublicComponents().size());
    656665    }
    657666
    658667    @Test
    659668    public void testUpdateProfile() throws Exception {
    660         List<ProfileDescription> profiles = getUserProfiles();
    661         assertEquals(0, profiles.size());
    662         assertEquals(0, getPublicProfiles().size());
    663 
    664         FormDataMultiPart form = createFormData(RegistryTestHelper.getTestProfileContent());
    665         ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true"))
    666                 .type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
    667         assertEquals(ClientResponse.Status.OK.getStatusCode(), cResponse.getStatus());
    668         RegisterResponse response = cResponse.getEntity(RegisterResponse.class);
    669         assertTrue(response.isRegistered());
    670         assertTrue(response.isProfile());
    671         assertTrue(response.isInUserSpace());
    672         ProfileDescription desc = (ProfileDescription) response.getDescription();
    673         assertNotNull(desc);
    674         assertEquals("Test1", desc.getName());
    675         assertEquals("My Test", desc.getDescription());
    676         assertEquals("TestGroup", desc.getGroupName());
    677         Date firstDate = AbstractDescription.getDate(desc.getRegistrationDate());
    678         CMDComponentSpec spec = getUserProfile(desc);
    679         assertNotNull(spec);
    680         assertEquals("Actor", spec.getCMDComponent().get(0).getName());
    681         profiles = getUserProfiles();
    682         assertEquals(1, profiles.size());
    683         assertEquals(0, getPublicComponents().size());
    684 
    685         //Now update
    686         form = createFormData(RegistryTestHelper.getTestProfileContent("TESTNAME"), "UPDATE DESCRIPTION!");
    687         cResponse = getAuthenticatedResource(
    688                 getResource().path("/registry/profiles/" + desc.getId() + "/update").queryParam(USERSPACE_PARAM, "true")).type(
    689                 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
    690         assertEquals(ClientResponse.Status.OK.getStatusCode(), cResponse.getStatus());
    691         response = cResponse.getEntity(RegisterResponse.class);
    692         assertTrue(response.isRegistered());
    693         assertTrue(response.isProfile());
    694         assertTrue(response.isInUserSpace());
    695         desc = (ProfileDescription) response.getDescription();
    696         assertNotNull(desc);
    697         assertEquals("Test1", desc.getName());
    698         assertEquals("UPDATE DESCRIPTION!", desc.getDescription());
    699         Date secondDate = AbstractDescription.getDate(desc.getRegistrationDate());
    700         assertTrue(firstDate.before(secondDate) || firstDate.equals(secondDate));
    701 
    702         spec = getUserProfile(desc);
    703         assertNotNull(spec);
    704         assertEquals("TESTNAME", spec.getCMDComponent().get(0).getName());
    705         profiles = getUserProfiles();
    706         assertEquals(1, profiles.size());
    707         assertEquals(0, getPublicComponents().size());
     669        List<ProfileDescription> profiles = getUserProfiles();
     670        assertEquals(0, profiles.size());
     671        assertEquals(0, getPublicProfiles().size());
     672
     673        FormDataMultiPart form = createFormData(RegistryTestHelper.getTestProfileContent());
     674        ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")).type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
     675        assertEquals(ClientResponse.Status.OK.getStatusCode(), cResponse.getStatus());
     676        RegisterResponse response = cResponse.getEntity(RegisterResponse.class);
     677        assertTrue(response.isRegistered());
     678        assertTrue(response.isProfile());
     679        assertTrue(response.isInUserSpace());
     680        ProfileDescription desc = (ProfileDescription) response.getDescription();
     681        assertNotNull(desc);
     682        assertEquals("Test1", desc.getName());
     683        assertEquals("My Test", desc.getDescription());
     684        assertEquals("TestGroup", desc.getGroupName());
     685        Date firstDate = AbstractDescription.getDate(desc.getRegistrationDate());
     686        CMDComponentSpec spec = getUserProfile(desc);
     687        assertNotNull(spec);
     688        assertEquals("Actor", spec.getCMDComponent().get(0).getName());
     689        profiles = getUserProfiles();
     690        assertEquals(1, profiles.size());
     691        assertEquals(0, getPublicComponents().size());
     692
     693        //Now update
     694        form = createFormData(RegistryTestHelper.getTestProfileContent("TESTNAME"), "UPDATE DESCRIPTION!");
     695        cResponse = getAuthenticatedResource(
     696                getResource().path("/registry/profiles/" + desc.getId() + "/update").queryParam(USERSPACE_PARAM, "true")).type(
     697                MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
     698        assertEquals(ClientResponse.Status.OK.getStatusCode(), cResponse.getStatus());
     699        response = cResponse.getEntity(RegisterResponse.class);
     700        assertTrue(response.isRegistered());
     701        assertTrue(response.isProfile());
     702        assertTrue(response.isInUserSpace());
     703        desc = (ProfileDescription) response.getDescription();
     704        assertNotNull(desc);
     705        assertEquals("Test1", desc.getName());
     706        assertEquals("UPDATE DESCRIPTION!", desc.getDescription());
     707        Date secondDate = AbstractDescription.getDate(desc.getRegistrationDate());
     708        assertTrue(firstDate.before(secondDate) || firstDate.equals(secondDate));
     709
     710        spec = getUserProfile(desc);
     711        assertNotNull(spec);
     712        assertEquals("TESTNAME", spec.getCMDComponent().get(0).getName());
     713        profiles = getUserProfiles();
     714        assertEquals(1, profiles.size());
     715        assertEquals(0, getPublicComponents().size());
    708716    }
    709717
    710718    private CMDComponentSpec getUserComponent(ComponentDescription desc) {
    711         return getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId()).queryParam(USERSPACE_PARAM, "true"))
    712                 .accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class);
     719        return getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId()).queryParam(USERSPACE_PARAM, "true")).accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class);
    713720    }
    714721
    715722    private CMDComponentSpec getUserProfile(ProfileDescription desc) {
    716         return getAuthenticatedResource(getResource().path("/registry/profiles/" + desc.getId()).queryParam(USERSPACE_PARAM, "true"))
    717                 .accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class);
     723        return getAuthenticatedResource(getResource().path("/registry/profiles/" + desc.getId()).queryParam(USERSPACE_PARAM, "true")).accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class);
    718724    }
    719725
    720726    private List<ComponentDescription> getPublicComponents() {
    721         return getAuthenticatedResource("/registry/components").accept(MediaType.APPLICATION_XML).get(COMPONENT_LIST_GENERICTYPE);
     727        return getAuthenticatedResource("/registry/components").accept(MediaType.APPLICATION_XML).get(COMPONENT_LIST_GENERICTYPE);
    722728    }
    723729
    724730    private List<ComponentDescription> getUserComponents() {
    725         return getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")).accept(
    726                 MediaType.APPLICATION_XML).get(COMPONENT_LIST_GENERICTYPE);
     731        return getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")).accept(
     732                MediaType.APPLICATION_XML).get(COMPONENT_LIST_GENERICTYPE);
    727733    }
    728734
    729735    @Test
    730736    public void testRegisterComponent() throws Exception {
    731         FormDataMultiPart form = new FormDataMultiPart();
    732         form.field(ComponentRegistryRestService.DATA_FORM_FIELD, RegistryTestHelper.getComponentTestContent(),
    733                 MediaType.APPLICATION_OCTET_STREAM_TYPE);
    734         form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "ComponentTest1");
    735         form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test Component");
    736         form.field(ComponentRegistryRestService.DOMAIN_FORM_FIELD, "TestDomain");
    737         form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup");
    738         RegisterResponse response = getAuthenticatedResource("/registry/components").type(MediaType.MULTIPART_FORM_DATA).post(
    739                 RegisterResponse.class, form);
    740         assertTrue(response.isRegistered());
    741         assertFalse(response.isProfile());
    742         assertFalse(response.isInUserSpace());
    743         ComponentDescription desc = (ComponentDescription) response.getDescription();
    744         assertNotNull(desc);
    745         assertEquals("ComponentTest1", desc.getName());
    746         assertEquals("My Test Component", desc.getDescription());
    747         assertEquals(expectedUserId("JUnit@test.com"), desc.getUserId());
    748         assertEquals("JUnit@test.com", desc.getCreatorName());
    749         assertEquals("TestGroup", desc.getGroupName());
    750         assertEquals("TestDomain", desc.getDomainName());
    751         assertTrue(desc.getId().startsWith(ComponentRegistry.REGISTRY_ID + "c_"));
    752         assertNotNull(desc.getRegistrationDate());
    753         String url = getResource().getUriBuilder().build().toString();
    754         assertEquals(url + "registry/components/" + desc.getId(), desc.getHref());
     737        FormDataMultiPart form = new FormDataMultiPart();
     738        form.field(ComponentRegistryRestService.DATA_FORM_FIELD, RegistryTestHelper.getComponentTestContent(),
     739                MediaType.APPLICATION_OCTET_STREAM_TYPE);
     740        form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "ComponentTest1");
     741        form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test Component");
     742        form.field(ComponentRegistryRestService.DOMAIN_FORM_FIELD, "TestDomain");
     743        form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup");
     744        RegisterResponse response = getAuthenticatedResource("/registry/components").type(MediaType.MULTIPART_FORM_DATA).post(
     745                RegisterResponse.class, form);
     746        assertTrue(response.isRegistered());
     747        assertFalse(response.isProfile());
     748        assertFalse(response.isInUserSpace());
     749        ComponentDescription desc = (ComponentDescription) response.getDescription();
     750        assertNotNull(desc);
     751        assertEquals("ComponentTest1", desc.getName());
     752        assertEquals("My Test Component", desc.getDescription());
     753        assertEquals(expectedUserId("JUnit@test.com"), desc.getUserId());
     754        assertEquals("JUnit@test.com", desc.getCreatorName());
     755        assertEquals("TestGroup", desc.getGroupName());
     756        assertEquals("TestDomain", desc.getDomainName());
     757        assertTrue(desc.getId().startsWith(ComponentRegistry.REGISTRY_ID + "c_"));
     758        assertNotNull(desc.getRegistrationDate());
     759        String url = getResource().getUriBuilder().build().toString();
     760        assertEquals(url + "registry/components/" + desc.getId(), desc.getHref());
     761    }
     762
     763    @Test
     764    public void testRegisterComment() throws Exception {
     765        FormDataMultiPart form = new FormDataMultiPart();
     766        form.field(ComponentRegistryRestService.DATA_FORM_FIELD, RegistryTestHelper.getCommentTestContent(),
     767                MediaType.APPLICATION_OCTET_STREAM_TYPE);
     768        fillUp();
     769        RegisterResponse response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile1/comments").type(MediaType.MULTIPART_FORM_DATA).post(
     770                RegisterResponse.class, form);
     771        assertFalse(response.isInUserSpace());
     772        Comment comment = (Comment) response.getComment();
     773        assertNotNull(comment);
     774        assertEquals("CommentTest1", comment.getComment());
     775        assertEquals(expectedUserId("JUnit@test.com"), comment.getUserId());
     776        assertTrue(comment.getId().startsWith(ComponentRegistry.REGISTRY_ID + "p_"));
     777        assertNotNull(comment.getCommentDate());
     778        String url = getResource().getUriBuilder().build().toString();
     779        assertEquals(url + "registry/profiles/{clarin.eu:cr1:p_1297242111880}/comments/" + comment.getId(), 1);
    755780    }
    756781
    757782    @Test
    758783    public void testRegisterProfileInvalidData() throws Exception {
    759         FormDataMultiPart form = new FormDataMultiPart();
    760         String notAValidProfile = "<CMD_ComponentSpec> </CMD_ComponentSpec>";
    761         form.field(ComponentRegistryRestService.DATA_FORM_FIELD, new ByteArrayInputStream(notAValidProfile.getBytes()),
    762                 MediaType.APPLICATION_OCTET_STREAM_TYPE);
    763         form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "ProfileTest1");
    764         form.field(ComponentRegistryRestService.DOMAIN_FORM_FIELD, "Domain");
    765         form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, "Group");
    766         form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test Profile");
    767         RegisterResponse postResponse = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
    768                 RegisterResponse.class, form);
    769         assertTrue(postResponse.isProfile());
    770         assertFalse(postResponse.isRegistered());
    771         assertEquals(1, postResponse.getErrors().size());
    772         assertTrue(postResponse.getErrors().get(0).contains("SAXParseException"));
     784        FormDataMultiPart form = new FormDataMultiPart();
     785        String notAValidProfile = "<CMD_ComponentSpec> </CMD_ComponentSpec>";
     786        form.field(ComponentRegistryRestService.DATA_FORM_FIELD, new ByteArrayInputStream(notAValidProfile.getBytes()),
     787                MediaType.APPLICATION_OCTET_STREAM_TYPE);
     788        form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "ProfileTest1");
     789        form.field(ComponentRegistryRestService.DOMAIN_FORM_FIELD, "Domain");
     790        form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, "Group");
     791        form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test Profile");
     792        RegisterResponse postResponse = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
     793                RegisterResponse.class, form);
     794        assertTrue(postResponse.isProfile());
     795        assertFalse(postResponse.isRegistered());
     796        assertEquals(1, postResponse.getErrors().size());
     797        assertTrue(postResponse.getErrors().get(0).contains("SAXParseException"));
    773798    }
    774799
    775800    @Test
    776801    public void testRegisterProfileInvalidDescriptionAndContent() throws Exception {
    777         FormDataMultiPart form = new FormDataMultiPart();
    778         String profileContent = "";
    779         profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    780         profileContent += "<CMD_ComponentSpec> \n"; //No isProfile attribute
    781         profileContent += "    <Header />\n";
    782         profileContent += "    <CMD_Component name=\"Actor\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n";
    783         profileContent += "        <AttributeList>\n";
    784         profileContent += "            <Attribute>\n";
    785         profileContent += "                <Name>Name</Name>\n";
    786         profileContent += "                <Type>string</Type>\n";
    787         profileContent += "            </Attribute>\n";
    788         profileContent += "        </AttributeList>\n";
    789         profileContent += "    </CMD_Component>\n";
    790         profileContent += "</CMD_ComponentSpec>\n";
    791         form.field("data", new ByteArrayInputStream(profileContent.getBytes()), MediaType.APPLICATION_OCTET_STREAM_TYPE);
    792         form.field("name", "");//Empty name so invalid
    793         form.field("description", "My Test Profile");
    794         RegisterResponse response = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
    795                 RegisterResponse.class, form);
    796         assertFalse(response.isRegistered());
    797         assertEquals(2, response.getErrors().size());
    798         assertNotNull(response.getErrors().get(0));
    799         assertEquals(MDValidator.PARSE_ERROR, response.getErrors().get(1).substring(0, MDValidator.PARSE_ERROR.length()));
     802        FormDataMultiPart form = new FormDataMultiPart();
     803        String profileContent = "";
     804        profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     805        profileContent += "<CMD_ComponentSpec> \n"; //No isProfile attribute
     806        profileContent += "    <Header />\n";
     807        profileContent += "    <CMD_Component name=\"Actor\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n";
     808        profileContent += "        <AttributeList>\n";
     809        profileContent += "            <Attribute>\n";
     810        profileContent += "                <Name>Name</Name>\n";
     811        profileContent += "                <Type>string</Type>\n";
     812        profileContent += "            </Attribute>\n";
     813        profileContent += "        </AttributeList>\n";
     814        profileContent += "    </CMD_Component>\n";
     815        profileContent += "</CMD_ComponentSpec>\n";
     816        form.field("data", new ByteArrayInputStream(profileContent.getBytes()), MediaType.APPLICATION_OCTET_STREAM_TYPE);
     817        form.field("name", "");//Empty name so invalid
     818        form.field("description", "My Test Profile");
     819        RegisterResponse response = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
     820                RegisterResponse.class, form);
     821        assertFalse(response.isRegistered());
     822        assertEquals(2, response.getErrors().size());
     823        assertNotNull(response.getErrors().get(0));
     824        assertEquals(MDValidator.PARSE_ERROR, response.getErrors().get(1).substring(0, MDValidator.PARSE_ERROR.length()));
    800825    }
    801826
    802827    @Test
    803828    public void testRegisterComponentAsProfile() throws Exception {
    804         FormDataMultiPart form = new FormDataMultiPart();
    805         form.field(ComponentRegistryRestService.DATA_FORM_FIELD, RegistryTestHelper.getComponentTestContent(),
    806                 MediaType.APPLICATION_OCTET_STREAM_TYPE);
    807         form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "t");
    808         form.field(ComponentRegistryRestService.DOMAIN_FORM_FIELD, "domain");
    809         form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test");
    810         form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, "My Group");
    811         RegisterResponse response = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
    812                 RegisterResponse.class, form);
    813         assertFalse(response.isRegistered());
    814         assertTrue(response.isProfile());
    815         assertEquals(1, response.getErrors().size());
    816         assertEquals(MDValidator.MISMATCH_ERROR, response.getErrors().get(0));
    817     }
    818 
     829        FormDataMultiPart form = new FormDataMultiPart();
     830        form.field(ComponentRegistryRestService.DATA_FORM_FIELD, RegistryTestHelper.getComponentTestContent(),
     831                MediaType.APPLICATION_OCTET_STREAM_TYPE);
     832        form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "t");
     833        form.field(ComponentRegistryRestService.DOMAIN_FORM_FIELD, "domain");
     834        form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test");
     835        form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, "My Group");
     836        RegisterResponse response = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
     837                RegisterResponse.class, form);
     838        assertFalse(response.isRegistered());
     839        assertTrue(response.isProfile());
     840        assertEquals(1, response.getErrors().size());
     841        assertEquals(MDValidator.MISMATCH_ERROR, response.getErrors().get(0));
     842    }
    819843}
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTestCase.java

    r1419 r1635  
    77
    88import clarin.cmdi.componentregistry.impl.database.UserDao;
     9import clarin.cmdi.componentregistry.model.Comment;
    910import clarin.cmdi.componentregistry.model.ComponentDescription;
    1011import clarin.cmdi.componentregistry.model.ProfileDescription;
     
    3334    };
    3435    protected final static GenericType<List<ComponentDescription>> COMPONENT_LIST_GENERICTYPE = new GenericType<List<ComponentDescription>>() {
     36    };
     37    protected final static GenericType<List<Comment>> COMMENT_LIST_GENERICTYPE = new GenericType<List<Comment>>() {
    3538    };
    3639
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/RegistryTestHelper.java

    r1562 r1635  
    1515import clarin.cmdi.componentregistry.MDMarshaller;
    1616import clarin.cmdi.componentregistry.components.CMDComponentSpec;
     17import clarin.cmdi.componentregistry.model.Comment;
    1718import clarin.cmdi.componentregistry.model.ComponentDescription;
    1819import clarin.cmdi.componentregistry.model.ProfileDescription;
     
    2829
    2930    public static ComponentDescription addComponent(ComponentRegistry testRegistry, String id) throws ParseException, JAXBException {
    30         return addComponent(testRegistry, id, getComponentTestContent());
     31        return addComponent(testRegistry, id, getComponentTestContent());
    3132    }
    3233
    3334    public static ComponentDescription addComponent(ComponentRegistry testRegistry, String id, String content) throws ParseException,
    34             JAXBException, UnsupportedEncodingException {
    35         return addComponent(testRegistry, id, new ByteArrayInputStream(content.getBytes("UTF-8")));
     35            JAXBException, UnsupportedEncodingException {
     36        return addComponent(testRegistry, id, new ByteArrayInputStream(content.getBytes("UTF-8")));
    3637    }
    3738
    3839    private static ComponentDescription addComponent(ComponentRegistry testRegistry, String id, InputStream content) throws ParseException,
    39             JAXBException {
    40         ComponentDescription desc = ComponentDescription.createNewDescription();
    41         desc.setCreatorName(DummyPrincipal.DUMMY_CREDENTIALS.getDisplayName());
    42         desc.setUserId(DummyPrincipal.DUMMY_CREDENTIALS.getPrincipalName());
    43         desc.setName(id);
    44         desc.setDescription("Test Description");
    45         desc.setId(ComponentRegistry.REGISTRY_ID + id);
    46         desc.setHref("link:" + ComponentRegistry.REGISTRY_ID + id);
    47         CMDComponentSpec spec = MDMarshaller.unmarshal(CMDComponentSpec.class, content, MDMarshaller.getCMDComponentSchema());
    48         testRegistry.register(desc, spec);
    49         return desc;
     40            JAXBException {
     41        ComponentDescription desc = ComponentDescription.createNewDescription();
     42        desc.setCreatorName(DummyPrincipal.DUMMY_CREDENTIALS.getDisplayName());
     43        desc.setUserId(DummyPrincipal.DUMMY_CREDENTIALS.getPrincipalName());
     44        desc.setName(id);
     45        desc.setDescription("Test Description");
     46        desc.setId(ComponentRegistry.REGISTRY_ID + id);
     47        desc.setHref("link:" + ComponentRegistry.REGISTRY_ID + id);
     48        CMDComponentSpec spec = MDMarshaller.unmarshal(CMDComponentSpec.class, content, MDMarshaller.getCMDComponentSchema());
     49        testRegistry.register(desc, spec);
     50        return desc;
    5051    }
    5152
    5253    public static int updateComponent(ComponentRegistry testRegistry, ComponentDescription description, String content) throws JAXBException {
    53         return testRegistry.update(description, getComponentFromString(content), DummyPrincipal.DUMMY_CREDENTIALS.getPrincipal(), true);
     54        return testRegistry.update(description, getComponentFromString(content), DummyPrincipal.DUMMY_CREDENTIALS.getPrincipal(), true);
    5455    }
    5556
    5657    public static String getProfileTestContentString() {
    57         return getProfileTestContentString("Actor");
     58        return getProfileTestContentString("Actor");
    5859    }
    5960
    6061    private static String getProfileTestContentString(String name) {
    61         String profileContent = "";
    62         profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    63         profileContent += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    64         profileContent += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    65         profileContent += "    <Header />\n";
    66         profileContent += "    <CMD_Component name=\"" + name + "\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n";
    67         profileContent += "        <AttributeList>\n";
    68         profileContent += "            <Attribute>\n";
    69         profileContent += "                <Name>Name</Name>\n";
    70         profileContent += "                <Type>string</Type>\n";
    71         profileContent += "            </Attribute>\n";
    72         profileContent += "        </AttributeList>\n";
    73         profileContent += "        <CMD_Element name=\"Age\">\n";
    74         profileContent += "            <ValueScheme>\n";
    75         profileContent += "                <pattern>[23][0-9]</pattern>\n";
    76         profileContent += "            </ValueScheme>\n";
    77         profileContent += "        </CMD_Element>\n";
    78         profileContent += "    </CMD_Component>\n";
    79         profileContent += "</CMD_ComponentSpec>\n";
    80         return profileContent;
     62        String profileContent = "";
     63        profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     64        profileContent += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     65        profileContent += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     66        profileContent += "    <Header />\n";
     67        profileContent += "    <CMD_Component name=\"" + name + "\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n";
     68        profileContent += "        <AttributeList>\n";
     69        profileContent += "            <Attribute>\n";
     70        profileContent += "                <Name>Name</Name>\n";
     71        profileContent += "                <Type>string</Type>\n";
     72        profileContent += "            </Attribute>\n";
     73        profileContent += "        </AttributeList>\n";
     74        profileContent += "        <CMD_Element name=\"Age\">\n";
     75        profileContent += "            <ValueScheme>\n";
     76        profileContent += "                <pattern>[23][0-9]</pattern>\n";
     77        profileContent += "            </ValueScheme>\n";
     78        profileContent += "        </CMD_Element>\n";
     79        profileContent += "    </CMD_Component>\n";
     80        profileContent += "</CMD_ComponentSpec>\n";
     81        return profileContent;
    8182    }
    8283
    8384    public static InputStream getTestProfileContent() {
    84         return getTestProfileContent("Actor");
     85        return getTestProfileContent("Actor");
    8586    }
    8687
    8788    public static InputStream getTestProfileContent(String name) {
    88         return new ByteArrayInputStream(getProfileTestContentString(name).getBytes());
     89        return new ByteArrayInputStream(getProfileTestContentString(name).getBytes());
    8990    }
    9091
    9192    public static ProfileDescription addProfile(ComponentRegistry testRegistry, String id) throws ParseException, JAXBException {
    92         return addProfile(testRegistry, id, RegistryTestHelper.getTestProfileContent());
     93        return addProfile(testRegistry, id, RegistryTestHelper.getTestProfileContent());
    9394    }
    9495
    9596    public static ProfileDescription addProfile(ComponentRegistry testRegistry, String id, String content) throws ParseException,
    96             JAXBException {
    97         return addProfile(testRegistry, id, new ByteArrayInputStream(content.getBytes()));
     97            JAXBException {
     98        return addProfile(testRegistry, id, new ByteArrayInputStream(content.getBytes()));
    9899    }
    99100
    100101    private static ProfileDescription addProfile(ComponentRegistry testRegistry, String id, InputStream content) throws ParseException,
    101             JAXBException {
    102         ProfileDescription desc = ProfileDescription.createNewDescription();
    103         desc.setCreatorName(DummyPrincipal.DUMMY_CREDENTIALS.getDisplayName());
    104         desc.setUserId(DummyPrincipal.DUMMY_CREDENTIALS.getPrincipalName());
    105         desc.setName(id);
    106         desc.setDescription("Test Description");
    107         desc.setId(ComponentRegistry.REGISTRY_ID + id);
    108         desc.setHref("link:" + ComponentRegistry.REGISTRY_ID + id);
    109         CMDComponentSpec spec = MDMarshaller.unmarshal(CMDComponentSpec.class, content, MDMarshaller.getCMDComponentSchema());
    110         testRegistry.register(desc, spec);
    111         return desc;
     102            JAXBException {
     103        ProfileDescription desc = ProfileDescription.createNewDescription();
     104        desc.setCreatorName(DummyPrincipal.DUMMY_CREDENTIALS.getDisplayName());
     105        desc.setUserId(DummyPrincipal.DUMMY_CREDENTIALS.getPrincipalName());
     106        desc.setName(id);
     107        desc.setDescription("Test Description");
     108        desc.setId(ComponentRegistry.REGISTRY_ID + id);
     109        desc.setHref("link:" + ComponentRegistry.REGISTRY_ID + id);
     110        CMDComponentSpec spec = MDMarshaller.unmarshal(CMDComponentSpec.class, content, MDMarshaller.getCMDComponentSchema());
     111        testRegistry.register(desc, spec);
     112        return desc;
    112113    }
    113114
    114115    public static CMDComponentSpec getTestProfile() throws JAXBException {
    115         return MDMarshaller.unmarshal(CMDComponentSpec.class, getTestProfileContent(), MDMarshaller.getCMDComponentSchema());
     116        return MDMarshaller.unmarshal(CMDComponentSpec.class, getTestProfileContent(), MDMarshaller.getCMDComponentSchema());
    116117    }
    117118
    118119    public static String getComponentTestContentString() {
    119         return getComponentTestContentString("Access");
     120        return getComponentTestContentString("Access");
    120121    }
    121122
    122123    public static InputStream getComponentTestContent() {
    123         return getComponentTestContent("Access");
     124        return getComponentTestContent("Access");
    124125    }
    125126
    126127    public static String getComponentTestContentString(String componentName) {
    127         String compContent = "";
    128         compContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    129         compContent += "\n";
    130         compContent += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    131         compContent += "    xsi:noNamespaceSchemaLocation=\"../../general-component-schema.xsd\">\n";
    132         compContent += "    \n";
    133         compContent += "    <Header/>\n";
    134         compContent += "    \n";
    135         compContent += "    <CMD_Component name=\"" + componentName + "\" CardinalityMin=\"1\" CardinalityMax=\"1\">\n";
    136         compContent += "        <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n";
    137         compContent += "        <CMD_Element name=\"Date\">\n";
    138         compContent += "            <ValueScheme>\n";
    139         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";
    140         compContent += "                <pattern>(1|2)\\d{3}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])</pattern>                \n";
    141         compContent += "            </ValueScheme>\n";
    142         compContent += "        </CMD_Element>\n";
    143         compContent += "        <CMD_Element name=\"Owner\" ValueScheme=\"string\" />\n";
    144         compContent += "        <CMD_Element name=\"Publisher\" ValueScheme=\"string\" />\n";
    145         compContent += "    </CMD_Component>\n";
    146         compContent += "\n";
    147         compContent += "</CMD_ComponentSpec>\n";
    148         return compContent;
     128        String compContent = "";
     129        compContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     130        compContent += "\n";
     131        compContent += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     132        compContent += "    xsi:noNamespaceSchemaLocation=\"../../general-component-schema.xsd\">\n";
     133        compContent += "    \n";
     134        compContent += "    <Header/>\n";
     135        compContent += "    \n";
     136        compContent += "    <CMD_Component name=\"" + componentName + "\" CardinalityMin=\"1\" CardinalityMax=\"1\">\n";
     137        compContent += "        <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n";
     138        compContent += "        <CMD_Element name=\"Date\">\n";
     139        compContent += "            <ValueScheme>\n";
     140        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";
     141        compContent += "                <pattern>(1|2)\\d{3}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])</pattern>                \n";
     142        compContent += "            </ValueScheme>\n";
     143        compContent += "        </CMD_Element>\n";
     144        compContent += "        <CMD_Element name=\"Owner\" ValueScheme=\"string\" />\n";
     145        compContent += "        <CMD_Element name=\"Publisher\" ValueScheme=\"string\" />\n";
     146        compContent += "    </CMD_Component>\n";
     147        compContent += "\n";
     148        compContent += "</CMD_ComponentSpec>\n";
     149        return compContent;
    149150    }
    150151
    151152    public static CMDComponentSpec getComponentFromString(String contentString) throws JAXBException {
    152         return MDMarshaller.unmarshal(CMDComponentSpec.class, getComponentContent(contentString), MDMarshaller.getCMDComponentSchema());
     153        return MDMarshaller.unmarshal(CMDComponentSpec.class, getComponentContent(contentString), MDMarshaller.getCMDComponentSchema());
    153154    }
    154155
    155156    public static InputStream getComponentContent(String content) {
    156         return new ByteArrayInputStream(content.getBytes());
     157        return new ByteArrayInputStream(content.getBytes());
    157158    }
    158159
    159160    public static InputStream getComponentTestContent(String componentName) {
    160         return getComponentContent(getComponentTestContentString(componentName));
     161        return getComponentContent(getComponentTestContentString(componentName));
    161162    }
    162163
    163164    public static CMDComponentSpec getTestComponent() throws JAXBException {
    164         return MDMarshaller.unmarshal(CMDComponentSpec.class, getComponentTestContent(), MDMarshaller.getCMDComponentSchema());
     165        return MDMarshaller.unmarshal(CMDComponentSpec.class, getComponentTestContent(), MDMarshaller.getCMDComponentSchema());
    165166    }
    166167
    167168    public static CMDComponentSpec getTestComponent(String name) throws JAXBException {
    168         return MDMarshaller.unmarshal(CMDComponentSpec.class, getComponentTestContent(name), MDMarshaller.getCMDComponentSchema());
     169        return MDMarshaller.unmarshal(CMDComponentSpec.class, getComponentTestContent(name), MDMarshaller.getCMDComponentSchema());
    169170    }
    170171
    171172    public static String getXml(CMDComponentSpec componentSpec) throws JAXBException, UnsupportedEncodingException {
    172         ByteArrayOutputStream os = new ByteArrayOutputStream();
    173         MDMarshaller.marshal(componentSpec, os);
    174         String xml = os.toString();
    175         try {
    176             os.close();
    177         } catch (IOException ex) {
    178         }
    179         return xml;
     173        ByteArrayOutputStream os = new ByteArrayOutputStream();
     174        MDMarshaller.marshal(componentSpec, os);
     175        String xml = os.toString();
     176        try {
     177            os.close();
     178        } catch (IOException ex) {
     179        }
     180        return xml;
     181    }
     182
     183    public static Comment addComment(ComponentRegistry testRegistry, String id) throws ParseException, JAXBException {
     184        return addComment(testRegistry, id, RegistryTestHelper.getCommentTestContent());
     185    }
     186
     187//    public static Comment addComment(ComponentRegistry testRegistry, String id, String content) throws ParseException,
     188//            JAXBException {
     189//        return addComment(testRegistry, id, new ByteArrayInputStream(content.getBytes()));
     190//    }
     191
     192    private static Comment addComment(ComponentRegistry testRegistry, String id, InputStream content) throws ParseException,
     193            JAXBException {
     194        Comment com = Comment.createANewComment();
     195        com.setUserId(DummyPrincipal.DUMMY_CREDENTIALS.getPrincipalName());
     196        com.setId(id);
     197        com.setComment("Test Comment");
     198        Comment spec = MDMarshaller.unmarshal(Comment.class, content, null);
     199        testRegistry.registerComment(com, spec);
     200        return com;
     201    }
     202
     203    public static String getCommentTestContentString(String commentName) {
     204        String comContent = "";
     205        comContent += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
     206        comContent += "<comment xmlns:ns2=\"http://www.w3.org/1999/xlink\">\n";
     207        comContent += "    <comments>"+ commentName +"</comments>\n";
     208        comContent += "    <commentDate>myDate</commentDate>\n";
     209        comContent += "    <profileDescriptionId>profile1</profileDescriptionId>\n";
     210        comContent += "    <userId>8</userId>\n";
     211        comContent += "    <id>1</id>\n";
     212        comContent += "</comment>\n";
     213        return comContent;
     214    }
     215
     216    public static InputStream getTestCommentContent(String content) {
     217        return new ByteArrayInputStream(getCommentTestContentString(content).getBytes());
     218    }
     219
     220    public static String getCommentTestContent(String commentName) {
     221        return getCommentTestContentString("Actual");
     222    }
     223
     224    public static InputStream getCommentTestContent() {
     225        return getTestCommentContent("Actual");
    180226    }
    181227
     
    185231     */
    186232    public static boolean hasComponent(String xsd, String name, String min, String max) {
    187         Pattern pattern = Pattern.compile("<xs:element name=\"" + name + "\" minOccurs=\"" + min + "\" maxOccurs=\"" + max + "\">");
    188         Matcher matcher = pattern.matcher(xsd);
    189         return matcher.find() && !matcher.find(); //find only one
     233        Pattern pattern = Pattern.compile("<xs:element name=\"" + name + "\" minOccurs=\"" + min + "\" maxOccurs=\"" + max + "\">");
     234        Matcher matcher = pattern.matcher(xsd);
     235        return matcher.find() && !matcher.find(); //find only one
    190236    }
    191237}
Note: See TracChangeset for help on using the changeset viewer.