Commit eeb270fe authored by Maxym Borodenko's avatar Maxym Borodenko

Test: not possible to set accessionNumber/inventoryNumber via API

parent 8175e3ef
......@@ -28,6 +28,7 @@ import java.util.List;
import org.apache.commons.lang3.RandomUtils;
import org.genesys.blocks.model.JsonViews;
import org.gringlobal.api.v1.impl.AccessionController;
import org.gringlobal.component.GGCE;
import org.gringlobal.model.*;
import org.gringlobal.persistence.AccessionInvGroupMapRepository;
import org.gringlobal.persistence.AccessionInvGroupRepository;
......@@ -150,7 +151,7 @@ public class AccessionControllerTest extends AbstractApiV1Test {
mockMvc
.perform(get(AccessionController.API_URL.concat("/details/{id}"), savedAccession.getId())
.contentType(MediaType.APPLICATION_JSON))
// .andDo(MockMvcResultHandlers.print())
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$", not(nullValue())))
......@@ -159,6 +160,7 @@ public class AccessionControllerTest extends AbstractApiV1Test {
.andExpect(jsonPath("$.modifiedBy", is(AbstractServicesTest.USER_CURATOR1_ID)))
.andExpect(jsonPath("$.ownedBy").isMap())
.andExpect(jsonPath("$.ownedBy.id", is(AbstractServicesTest.USER_CURATOR1_ID)))
.andExpect(jsonPath("$.accessionNumber", is(GGCE.accessionNumber(savedAccession))))
.andExpect(jsonPath("$.accessionNumberPart1", is(savedAccession.getAccessionNumberPart1())))
.andExpect(jsonPath("$.statusCode", is(savedAccession.getStatusCode())))
.andExpect(jsonPath("$.isBackedUp", is(TRUE)))
......@@ -321,7 +323,7 @@ public class AccessionControllerTest extends AbstractApiV1Test {
.perform(get(AccessionController.API_URL.concat("/auditlog/{id}?s=propertyName"), savedAccession.getId())
.contentType(MediaType.APPLICATION_JSON)
)
.andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.totalElements", greaterThan(0)))
.andExpect(jsonPath("$.sort[0]", not(nullValue())))
......@@ -336,4 +338,34 @@ public class AccessionControllerTest extends AbstractApiV1Test {
/*@formatter:on*/
}
@Test
public void testCreateAccessionWithAccessionNumber() throws Exception {
// build accession
Accession a = new Accession();
a.setAccessionNumberPart1("TVu");
a.setAccessionNumberPart2(1L);
a.setIsBackedUp(TRUE);
a.setIsCore(TRUE);
a.setIsWebVisible(TRUE);
a.setStatusCode(ACCESSION_STATUS_CODE);
a.setTaxonomySpecies(addTaxonomySpeciesToDB());
final String content = verboseMapper.writeValueAsString(a).replace("\"accessionNumber\":null", "\"accessionNumber\":\"mustNotBeSaved\"");
/*@formatter:off*/
mockMvc
.perform(post(AccessionController.API_URL)
.content(content)
.contentType(MediaType.APPLICATION_JSON)
)
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$", notNullValue()))
.andExpect(jsonPath("$.id", is(greaterThan(0))))
.andExpect(jsonPath("$.accessionNumber").exists())
.andExpect(jsonPath("$.accessionNumber", is(GGCE.accessionNumber(a))))
.andExpect(jsonPath("$.accessionNumberPart1", is("TVu")))
;
/*@formatter:on*/
}
}
......@@ -24,6 +24,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import org.genesys.blocks.auditlog.model.AuditAction;
import org.genesys.filerepository.model.RepositoryImage;
import org.gringlobal.api.v1.impl.InventoryController;
import org.gringlobal.component.GGCE;
import org.gringlobal.model.Accession;
import org.gringlobal.model.AccessionInvAttach;
import org.gringlobal.model.AccessionInvName;
......@@ -503,6 +504,47 @@ public class InventoryControllerTest extends AbstractApiV1Test {
//assertThat(repositoryFileRepository.count(), is(0L));
}
@Test
public void testCreateWithInventoryNumber() throws Exception {
Accession accession = new Accession(makeAccession().getId());
assertThat(accession.getId(), is(greaterThan(0L)));
InventoryMaintenancePolicy policy = new InventoryMaintenancePolicy(addInventoryMaintenancePolicyToDB().getId());
assertThat(policy.getId(), is(greaterThan(0L)));
Inventory inventory = new Inventory();
inventory.setAccession(accession); // only ID
inventory.setInventoryMaintPolicy(policy); // only ID
inventory.setInventoryNumberPart1("INV");
inventory.setInventoryNumberPart2(1L);
inventory.setInventoryNumberPart3(null);
inventory.setFormTypeCode(INVENTORY_FORM_TYPE_CODE_DEFAULT);
inventory.setAvailabilityStatusCode(INVENTORY_AVAILABILITY_STATUS_CODE_DEFAULT);
inventory.setIsAutoDeducted(TRUE);
inventory.setIsAvailable(TRUE);
inventory.setIsDistributable(TRUE);
final String content = verboseMapper.writeValueAsString(inventory).replace("\"inventoryNumber\":null", "\"inventoryNumber\":\"mustNotBeSaved\"");
/*@formatter:off*/
mockMvc
.perform(post(InventoryController.API_URL)
.content(content)
.contentType(MediaType.APPLICATION_JSON)
)
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$", notNullValue()))
.andExpect(jsonPath("$.id", is(greaterThan(0))))
.andExpect(jsonPath("$.inventoryNumber").exists())
.andExpect(jsonPath("$.inventoryNumber", is(GGCE.inventoryNumber(inventory))))
.andExpect(jsonPath("$.inventoryNumberPart1", is("INV")))
.andExpect(jsonPath("$.inventoryNumberPart2", is(1)))
;
/*@formatter:on*/
}
private Accession makeAccession() {
Accession a = new Accession();
a.setAccessionNumberPart1("AccessionNumberPart1");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment