@Test public void testDeleteInstrumentByProjectId() throws Exception { // Arrange DataAcquisitionProject project = UnitTestCreateDomainObjectUtils.buildDataAcquisitionProject(); this.dataAcquisitionProjectRepository.save(project); Instrument instrument = UnitTestCreateDomainObjectUtils.buildInstrument(project.getId(), "SurveyId"); // create the instrument with the given id mockMvc .perform( put(API_INSTRUMENTS_URI + "/" + instrument.getId()) .content(TestUtil.convertObjectToJsonBytes(instrument))) .andExpect(status().isCreated()); // delete the instrument mockMvc .perform(post("/api/instruments/delete?dataAcquisitionProjectId=" + project.getId())) .andExpect(status().is2xxSuccessful()); // check that the instrument has been deleted as well mockMvc .perform(get(API_INSTRUMENTS_URI + "/" + instrument.getId())) .andExpect(status().isNotFound()); }
@Test public void testCreateWithWrongTitle() throws Exception { // Arrange DataAcquisitionProject project = UnitTestCreateDomainObjectUtils.buildDataAcquisitionProject(); this.dataAcquisitionProjectRepository.save(project); Instrument instrument = UnitTestCreateDomainObjectUtils.buildInstrument(project.getId(), "SurveyId"); // Act and Assert // set inconsistent title instrument.getTitle().setDe(""); ; // create the instrument with the given id mockMvc .perform( put(API_INSTRUMENTS_URI + "/" + instrument.getId()) .content(TestUtil.convertObjectToJsonBytes(instrument))) .andExpect(status().isBadRequest()) .andExpect( jsonPath( "$.errors[0].message", is("instrument-management.error.instrument.title.i18n-string-size"))); }
@Test public void testCreateRelatedPublications() throws IOException, Exception { // ARRANGE RelatedPublication relatedPublication = UnitTestCreateDomainObjectUtils.buildRelatedPublication(); // ACT // create the related publication with the given id this.mockMvc .perform( put(API_RELATED_PUBLICATION_URI + "/" + relatedPublication.getId()) .content(TestUtil.convertObjectToJsonBytes(relatedPublication))) .andExpect(status().isCreated()); // ASSERT // read the related publication under the new url this.mockMvc .perform(get(API_RELATED_PUBLICATION_URI + "/" + relatedPublication.getId())) .andExpect(status().isOk()); elasticsearchUpdateQueueService.processQueue(); // check that there are two data set documents plus two surveys elasticsearchAdminService.refreshAllIndices(); assertThat(elasticsearchAdminService.countAllDocuments(), equalTo(2.0)); }
@Test public void testUpdateInstrument() throws Exception { // Arrange DataAcquisitionProject project = UnitTestCreateDomainObjectUtils.buildDataAcquisitionProject(); this.dataAcquisitionProjectRepository.save(project); Instrument instrument = UnitTestCreateDomainObjectUtils.buildInstrument(project.getId(), "SurveyId"); // Act and Assert // create the instrument with the given id mockMvc .perform( put(API_INSTRUMENTS_URI + "/" + instrument.getId()) .content(TestUtil.convertObjectToJsonBytes(instrument))) .andExpect(status().isCreated()); instrument.setTitle(new I18nString("Hurz2", "Hurz2")); // update the instrument with the given id mockMvc .perform( put(API_INSTRUMENTS_URI + "/" + instrument.getId()) .content(TestUtil.convertObjectToJsonBytes(instrument))) .andExpect(status().is2xxSuccessful()); // read the updated instrument and check the version mockMvc .perform(get(API_INSTRUMENTS_URI + "/" + instrument.getId() + "?projection=complete")) .andExpect(status().isOk()) .andExpect(jsonPath("$.id", is(instrument.getId()))) .andExpect(jsonPath("$.version", is(1))) .andExpect(jsonPath("$.title.de", is("Hurz2"))); elasticsearchUpdateQueueService.processQueue(); // check that there are two instrument documents elasticsearchAdminService.refreshAllIndices(); assertThat(elasticsearchAdminService.countAllDocuments(), equalTo(2.0)); }
@Test public void testCreateInstrument() throws Exception { // Arrange DataAcquisitionProject project = UnitTestCreateDomainObjectUtils.buildDataAcquisitionProject(); this.dataAcquisitionProjectRepository.save(project); Instrument instrument = UnitTestCreateDomainObjectUtils.buildInstrument(project.getId(), "SurveyId"); // Act and Assert // create the instrument with the given id mockMvc .perform( put(API_INSTRUMENTS_URI + "/" + instrument.getId()) .content(TestUtil.convertObjectToJsonBytes(instrument))) .andExpect(status().isCreated()); elasticsearchUpdateQueueService.processQueue(); // check that there are two instrument documents elasticsearchAdminService.refreshAllIndices(); assertThat(elasticsearchAdminService.countAllDocuments(), equalTo(2.0)); // check that auditing attributes have been set mockMvc .perform(get(API_INSTRUMENTS_URI + "/" + instrument.getId())) .andExpect(status().isOk()) .andExpect(jsonPath("$.createdDate", not(isEmptyOrNullString()))) .andExpect(jsonPath("$.lastModifiedDate", not(isEmptyOrNullString()))) .andExpect(jsonPath("$.createdBy", is("system"))) .andExpect(jsonPath("$.lastModifiedBy", is("system"))); // call toString for test coverage :-| instrument.toString(); }
@Test public void testUpdateStudyWithInvalidReleaseDoi() throws IOException, Exception { // ARRANGE RelatedPublication relatedPublication = UnitTestCreateDomainObjectUtils.buildRelatedPublication(); relatedPublication.setDoi( "ThisDoiIsTooLong.ThisDoiIsTooLong.ThisDoiIsTooLong.ThisDoiIsTooLong.ThisDoiIsTooLong.ThisDoiIsTooLong.ThisDoiIsTooLong." + "ThisDoiIsTooLong.ThisDoiIsTooLong.ThisDoiIsTooLong.ThisDoiIsTooLong.ThisDoiIsTooLong."); // ACT and ASSERT // create the related publication with the given id this.mockMvc .perform( put(API_RELATED_PUBLICATION_URI + "/" + relatedPublication.getId()) .content(TestUtil.convertObjectToJsonBytes(relatedPublication))) .andExpect(status().is4xxClientError()); }