@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();
  }
 @Before
 public void setup() {
   this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
   elasticsearchAdminService.recreateAllIndices();
 }