Search in sources :

Example 36 with Json

use of com.b2international.commons.json.Json in project snow-owl by b2ihealthcare.

the class SnomedRefSetMemberApiTest method issue_SO_2501_ioobe_during_member_deletion.

/**
 * Removals are sent in a BulkRequest which includes individual DeleteRequests for each member to be deleted. The version of SnomedEditingContext prior to the fix, however, used
 * a server-side query to determine the list index for each member, and the list index reported by the database become misaligned with the actual
 * contents if the members were not removed in decreasing index order. This test verifies that order of delete requests inside a bulk request does not matter.
 */
@Test
public void issue_SO_2501_ioobe_during_member_deletion() throws Exception {
    String simpleRefSetId = createNewRefSet(branchPath);
    final Json memberRequest = Json.object(SnomedRf2Headers.FIELD_MODULE_ID, Concepts.MODULE_SCT_CORE, "refsetId", simpleRefSetId, SnomedRf2Headers.FIELD_REFERENCED_COMPONENT_ID, simpleRefSetId, "commitComment", "Created new simple reference set member");
    final String member1Id = assertCreated(createComponent(branchPath, SnomedComponentType.MEMBER, memberRequest));
    final String member2Id = assertCreated(createComponent(branchPath, SnomedComponentType.MEMBER, memberRequest));
    final String member3Id = assertCreated(createComponent(branchPath, SnomedComponentType.MEMBER, memberRequest));
    final BulkRequestBuilder<TransactionContext> bulk = BulkRequest.create();
    bulk.add(SnomedRequests.prepareDeleteMember(member1Id));
    bulk.add(SnomedRequests.prepareDeleteMember(member3Id));
    SnomedRequests.prepareCommit().setBody(bulk).setCommitComment("Delete reference set members in ascending index order").setAuthor("test").build(branchPath.getPath()).execute(Services.bus()).getSync();
    // Check that member 2 still exists
    getComponent(branchPath, SnomedComponentType.MEMBER, member2Id).statusCode(200);
}
Also used : TransactionContext(com.b2international.snowowl.core.domain.TransactionContext) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Json(com.b2international.commons.json.Json) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 37 with Json

use of com.b2international.commons.json.Json in project snow-owl by b2ihealthcare.

the class SnomedRefSetMemberApiTest method executeInvalidAction.

@Test
public void executeInvalidAction() throws Exception {
    String queryRefSetId = createNewRefSet(branchPath, SnomedRefSetType.QUERY);
    String simpleRefSetId = createNewRefSet(branchPath);
    final Json memberRequest = Json.object(SnomedRf2Headers.FIELD_MODULE_ID, Concepts.MODULE_SCT_CORE, "refsetId", queryRefSetId, SnomedRf2Headers.FIELD_REFERENCED_COMPONENT_ID, simpleRefSetId, SnomedRf2Headers.FIELD_QUERY, "<" + Concepts.REFSET_ROOT_CONCEPT, "commitComment", "Created new query reference set member");
    final String memberId = assertCreated(createComponent(branchPath, SnomedComponentType.MEMBER, memberRequest));
    getComponent(branchPath, SnomedComponentType.MEMBER, memberId).statusCode(200);
    final Json invalidActionRequest = Json.object("action", "invalid", "commitComment", "Executed invalid action on reference set member");
    executeMemberAction(branchPath, memberId, invalidActionRequest).statusCode(400).body("message", containsString("Invalid")).body("message", containsString("CREATE")).body("message", containsString("UPDATE")).body("message", containsString("DELETE")).body("message", containsString("SYNC"));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Json(com.b2international.commons.json.Json) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 38 with Json

use of com.b2international.commons.json.Json in project snow-owl by b2ihealthcare.

the class SnomedRefSetMemberApiTest method createMRCMModuleScopeMember.

@Test
public void createMRCMModuleScopeMember() {
    String newIdentifierConceptId = createNewConcept(branchPath, SnomedRefSetUtil.getParentConceptId(SnomedRefSetType.MRCM_MODULE_SCOPE));
    createNewRefSet(branchPath, SnomedRefSetType.MRCM_MODULE_SCOPE, newIdentifierConceptId);
    Json requestBody = createRefSetMemberRequestBody(newIdentifierConceptId, Concepts.ROOT_CONCEPT).with(SnomedRf2Headers.FIELD_MRCM_RULE_REFSET_ID, Concepts.ROOT_CONCEPT).with("commitComment", "Created new reference set member");
    String memberId = assertCreated(createComponent(branchPath, SnomedComponentType.MEMBER, requestBody));
    getComponent(branchPath, SnomedComponentType.MEMBER, memberId).statusCode(200).body(SnomedRf2Headers.FIELD_MRCM_RULE_REFSET_ID, equalTo(Concepts.ROOT_CONCEPT));
    Json requestBody2 = createRefSetMemberRequestBody(newIdentifierConceptId, Concepts.ROOT_CONCEPT).with(SnomedRf2Headers.FIELD_MRCM_RULE_REFSET_ID, // XXX batman should not be in the test dataset
    "159725002").with("commitComment", "Created new reference set member");
    createComponent(branchPath, SnomedComponentType.MEMBER, requestBody2).statusCode(400);
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Json(com.b2international.commons.json.Json) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 39 with Json

use of com.b2international.commons.json.Json in project snow-owl by b2ihealthcare.

the class SnomedRefSetMemberParameterizedTest method rejectMismatchedComponentType.

@Test
public void rejectMismatchedComponentType() throws Exception {
    String refSetId = getOrCreateRefSet(branchPath, refSetType);
    String referencedComponentType = getFirstAllowedReferencedComponentType(refSetType);
    for (String disallowedComponentType : REFERENCED_COMPONENT_TYPES) {
        if (!referencedComponentType.equals(disallowedComponentType)) {
            String referencedComponentId = getFirstMatchingReferencedComponent(branchPath, disallowedComponentType);
            Json requestBody = createRefSetMemberRequestBody(refSetId, referencedComponentId).with(getValidProperties(refSetType, referencedComponentId)).with("commitComment", "Created new reference set member with mismatched referencedComponentId");
            String expectedMessage = String.format("'%s' reference set can't reference '%s | %s' component. Only '%s' components are allowed.", refSetId, referencedComponentId, disallowedComponentType, referencedComponentType);
            createComponent(branchPath, SnomedComponentType.MEMBER, requestBody).statusCode(400).body("message", equalTo(expectedMessage));
        }
    }
}
Also used : Json(com.b2international.commons.json.Json) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 40 with Json

use of com.b2international.commons.json.Json in project snow-owl by b2ihealthcare.

the class SnomedRefSetMemberParameterizedTest method updateMemberEffectiveTime.

@Test
public void updateMemberEffectiveTime() throws Exception {
    final Pair<String, String> member = createRefSetMember();
    final String memberId = member.getA();
    LocalDate effectiveTime = getNextAvailableEffectiveDate(SnomedContentRule.SNOMEDCT_ID);
    Json updateRequest = Json.object("effectiveTime", EffectiveTimes.format(effectiveTime, DateFormats.SHORT), "commitComment", "Updated effective time on reference set member without force flag");
    // The update does not go through anymore, rejected with an error
    updateRefSetComponent(branchPath, SnomedComponentType.MEMBER, memberId, updateRequest, false).statusCode(400);
}
Also used : Json(com.b2international.commons.json.Json) LocalDate(java.time.LocalDate) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Aggregations

Json (com.b2international.commons.json.Json)139 Test (org.junit.Test)134 AbstractSnomedApiTest (com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)111 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)33 LocalDate (java.time.LocalDate)17 RelationshipValue (com.b2international.snowowl.snomed.core.domain.RelationshipValue)11 SnomedDescription (com.b2international.snowowl.snomed.core.domain.SnomedDescription)11 SnomedReferenceSetMember (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)11 BaseResourceApiTest (com.b2international.snowowl.core.rest.BaseResourceApiTest)10 SnomedReferenceSetMembers (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers)10 CodeSystem (com.b2international.snowowl.core.codesystem.CodeSystem)7 ISnomedIdentifierService (com.b2international.snowowl.snomed.cis.ISnomedIdentifierService)6 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)6 SctId (com.b2international.snowowl.snomed.cis.domain.SctId)4 Pair (com.b2international.commons.Pair)3 ValidatableResponse (io.restassured.response.ValidatableResponse)3 File (java.io.File)3 NotFoundException (com.b2international.commons.exceptions.NotFoundException)2 IBranchPath (com.b2international.snowowl.core.api.IBranchPath)2 TransactionContext (com.b2international.snowowl.core.domain.TransactionContext)2