Search in sources :

Example 11 with Json

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

the class SnomedRefSetMemberParameterizedTest method rejectNonExistentRefSetId.

@Test
public void rejectNonExistentRefSetId() throws Exception {
    String refSetId = reserveComponentId(null, ComponentCategory.CONCEPT);
    String referencedComponentId = createReferencedComponent(branchPath, refSetType);
    Json requestBody = createRefSetMemberRequestBody(refSetId, referencedComponentId).with(getValidProperties(refSetType, referencedComponentId)).with("commitComment", "Created new reference set member with non-existent refSetId");
    createComponent(branchPath, SnomedComponentType.MEMBER, requestBody).statusCode(400);
}
Also used : Json(com.b2international.commons.json.Json) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 12 with Json

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

the class SnomedConceptApiTest method reactivateConceptWithExistingOWLAxiom.

@Test
public void reactivateConceptWithExistingOWLAxiom() throws Exception {
    final String conceptId = ApplicationContext.getServiceForClass(ISnomedIdentifierService.class).generate(null, ComponentCategory.CONCEPT, 1).iterator().next();
    final String owlSubclassOfExpression = String.format("SubClassOf(:%s :%s)", conceptId, Concepts.ROOT_CONCEPT);
    final String owlAxiomMemberId = UUID.randomUUID().toString();
    // create an inactive concept with an active OWL axiom
    Json conceptRequestBody = createConceptRequestBody(Concepts.FULLY_SPECIFIED_NAME).with(Json.object("id", conceptId, "active", false, "members", Json.array(Json.object("id", owlAxiomMemberId, "active", true, "moduleId", Concepts.MODULE_SCT_CORE, "refsetId", Concepts.REFSET_OWL_AXIOM, SnomedRf2Headers.FIELD_OWL_EXPRESSION, owlSubclassOfExpression)), "commitComment", "Created concept with owl axiom reference set member"));
    conceptRequestBody = conceptRequestBody.without("relationships");
    createConcept(branchPath, conceptRequestBody);
    // check the concept before reactivating, parentage info should be empty
    SnomedConcept concept = getConcept(conceptId);
    // assertThat(concept.getStatedAncestorIdsAsString()).isEmpty();
    // assertThat(concept.getStatedParentIdsAsString()).contains(IComponent.ROOT_ID);
    // reactivate concept and check stated parentage info
    reactivateConcept(branchPath, conceptId);
    // it should receive the necessary info to be part of the tree again
    concept = getConcept(conceptId);
    assertThat(concept.getStatedAncestorIdsAsString()).contains(IComponent.ROOT_ID);
    assertThat(concept.getStatedParentIdsAsString()).contains(Concepts.ROOT_CONCEPT);
}
Also used : ISnomedIdentifierService(com.b2international.snowowl.snomed.cis.ISnomedIdentifierService) Json(com.b2international.commons.json.Json) Test(org.junit.Test)

Example 13 with Json

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

the class SnomedConceptApiTest method testUpdateConceptDefinitionStatusWithSubClassOfAxiomMemberShouldChangeToPrimitive.

@Test
public void testUpdateConceptDefinitionStatusWithSubClassOfAxiomMemberShouldChangeToPrimitive() {
    final String conceptId = createNewConcept(branchPath);
    // Update the definition status on concept
    final Map<?, ?> definitionStatusUpdateRequestBody = Json.object("definitionStatusId", Concepts.FULLY_DEFINED, "commitComment", "Changed definition status of concept to fully defined");
    updateComponent(branchPath, SnomedComponentType.CONCEPT, conceptId, definitionStatusUpdateRequestBody).statusCode(204);
    // Add a reference set member
    final SnomedReferenceSetMember newMember = new SnomedReferenceSetMember();
    newMember.setId(UUID.randomUUID().toString());
    newMember.setActive(true);
    newMember.setRefsetId(Concepts.REFSET_OWL_AXIOM);
    newMember.setProperties(Json.object(SnomedRf2Headers.FIELD_OWL_EXPRESSION, String.format("SubClassOf(:%s :%s)", conceptId, Concepts.AMBIGUOUS)));
    newMember.setType(SnomedRefSetType.OWL_AXIOM);
    newMember.setModuleId(Concepts.MODULE_SCT_CORE);
    final Json updateRequestBody = Json.object("members", SnomedReferenceSetMembers.of(Json.array(newMember)), "commitComment", "Add new reference set member via concept update");
    updateComponent(branchPath, SnomedComponentType.CONCEPT, conceptId, updateRequestBody).statusCode(204);
    final SnomedConcept updatedConcept = getComponent(branchPath, SnomedComponentType.CONCEPT, conceptId, "members()").statusCode(200).extract().as(SnomedConcept.class);
    assertEquals(1, updatedConcept.getMembers().getTotal());
    // Verify that definition status was updated to FULLY DEFINED
    assertEquals(Concepts.PRIMITIVE, updatedConcept.getDefinitionStatusId());
}
Also used : SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) Json(com.b2international.commons.json.Json) Test(org.junit.Test)

Example 14 with Json

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

the class SnomedConceptApiTest method testUpdateConceptDefinitionStatusWithAxiomMembersShouldNotChange.

@Test
public void testUpdateConceptDefinitionStatusWithAxiomMembersShouldNotChange() {
    final String conceptId = createNewConcept(branchPath);
    // Update the definition status on concept
    final Map<?, ?> definitionStatusUpdateRequestBody = Json.object("definitionStatusId", Concepts.FULLY_DEFINED, "commitComment", "Changed definition status of concept to fully defined");
    updateComponent(branchPath, SnomedComponentType.CONCEPT, conceptId, definitionStatusUpdateRequestBody).statusCode(204);
    // Add a reference set member
    final SnomedReferenceSetMember newMember = new SnomedReferenceSetMember();
    newMember.setId(UUID.randomUUID().toString());
    newMember.setActive(true);
    newMember.setRefsetId(Concepts.REFSET_OWL_AXIOM);
    newMember.setProperties(Json.object(SnomedRf2Headers.FIELD_OWL_EXPRESSION, String.format("EquivalentClasses(:%s ObjectIntersectionOf(:%s :%s))", conceptId, Concepts.AMBIGUOUS, Concepts.NAMESPACE_ROOT)));
    newMember.setType(SnomedRefSetType.OWL_AXIOM);
    newMember.setModuleId(Concepts.MODULE_SCT_CORE);
    final Json updateRequestBody = Json.object("members", SnomedReferenceSetMembers.of(Json.array(newMember)), "definitionStatusId", Concepts.PRIMITIVE, "commitComment", "Add new reference set member via concept update");
    updateComponent(branchPath, SnomedComponentType.CONCEPT, conceptId, updateRequestBody).statusCode(204);
    final SnomedConcept updatedConcept = getComponent(branchPath, SnomedComponentType.CONCEPT, conceptId, "members()").statusCode(200).extract().as(SnomedConcept.class);
    assertEquals(1, updatedConcept.getMembers().getTotal());
    // Verify that definition status is still fully defined
    assertEquals(Concepts.FULLY_DEFINED, updatedConcept.getDefinitionStatusId());
}
Also used : SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) Json(com.b2international.commons.json.Json) Test(org.junit.Test)

Example 15 with Json

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

the class SnomedConceptInactivationApiTest method toggleDefinitionStatusAtStatusChange.

@Test
public void toggleDefinitionStatusAtStatusChange() {
    String conceptId = createNewConcept(branchPath);
    Json requestBody = createRefSetMemberRequestBody(Concepts.REFSET_OWL_AXIOM, conceptId).with(SnomedRf2Headers.FIELD_OWL_EXPRESSION, "EquivalentClasses(:" + conceptId + " :" + Concepts.NAMESPACE_ROOT + ")").with("commitComment", "Created new equivalent class OWL Axiom reference set member");
    assertCreated(createComponent(branchPath, SnomedComponentType.MEMBER, requestBody));
    SnomedReferenceSetMembers members = SnomedComponentRestRequests.searchComponent(branchPath, SnomedComponentType.MEMBER, Map.of("referencedComponentId", conceptId)).extract().as(SnomedReferenceSetMembers.class);
    updateComponent(branchPath, SnomedComponentType.CONCEPT, conceptId, Json.object("members", members, "commitComment", "Update concept members")).statusCode(204);
    SnomedConcept concept = assertGetConcept(conceptId).statusCode(200).extract().as(SnomedConcept.class);
    assertTrue(concept.isActive());
    // Active concept is defined after adding equivalent class axioms to it
    assertTrue(!concept.isPrimitive());
    inactivateConcept(branchPath, conceptId);
    concept = assertGetConcept(conceptId).statusCode(200).extract().as(SnomedConcept.class);
    assertTrue(!concept.isActive());
    // Inactive concept becomes primitive
    assertTrue(concept.isPrimitive());
    updateComponent(branchPath, SnomedComponentType.CONCEPT, conceptId, Json.object("active", true, "commitComment", "Reactivate concept")).statusCode(204);
    concept = assertGetConcept(conceptId).statusCode(200).extract().as(SnomedConcept.class);
    assertTrue(concept.isActive());
    // Reactivated concept with no active members stays primitive
    assertTrue(concept.isPrimitive());
}
Also used : SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) Json(com.b2international.commons.json.Json) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) 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