Skip to content

Commit

Permalink
MODRS-42 - Unable to view configuration edits in third pane (#69)
Browse files Browse the repository at this point in the history
* MODRS-42
# Fixing caching mechanism for PUT

* MODRS-42 - disable cache logic

* MODRS-42 - enable get method checking

* MODRS-42 - fix misprint

Co-authored-by: Aliaksei_Harbuz <[email protected]>
  • Loading branch information
khandramai and alekGbuz committed Apr 19, 2021
1 parent 02b65bd commit 83894d3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
7 changes: 4 additions & 3 deletions src/main/java/org/folio/rs/service/ConfigurationsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ public StorageConfiguration postConfiguration(StorageConfiguration storageConfig

@CachePut(value = CONFIGURATIONS, key = "#storageConfiguration.id")
public StorageConfiguration updateConfiguration(String id, StorageConfiguration storageConfiguration) {
Configuration configuration;
if (id.equals(storageConfiguration.getId())) {
var configuration = configurationsMapper.mapDtoToEntity(storageConfiguration);
configurationsRepository.save(copyForUpdate(configurationsRepository.getOne(configuration.getId()), configuration));
var conf = configurationsMapper.mapDtoToEntity(storageConfiguration);
configuration = configurationsRepository.save(copyForUpdate(configurationsRepository.getOne(conf.getId()), conf));
} else {
throw new IdMismatchException();
}
return storageConfiguration;
return configurationsMapper.mapEntityToDto(configuration);
}

private Configuration copyForUpdate(Configuration dest, Configuration source) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
spring:
cache:
type: none
application:
name: @project.artifactId@
version: @project.version@
Expand Down
18 changes: 9 additions & 9 deletions src/test/java/org/folio/rs/controller/ConfigurationsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ void canPostConfiguration() {
assertThat(responseEntity.getBody().getMetadata().getCreatedDate(), notNullValue());
assertThat(fetchConfigurations().getTotalRecords(), is(2));

// Verify caching
// Verify caching disable via MODRS-42
StorageConfiguration configuration = get(configurationsUrl + "/" + responseEntity.getBody().getId(), StorageConfiguration.class).getBody();
assertTrue(EqualsBuilder.reflectionEquals(responseEntity.getBody(), configuration, true, StorageConfiguration.class, "metadata"));
assertTrue(EqualsBuilder.reflectionEquals(
requireNonNull(
requireNonNull(cacheManager.getCache("configurations")).get(responseEntity.getBody().getId())).get(), configuration, true, StorageConfiguration.class, "metadata"));
// assertTrue(EqualsBuilder.reflectionEquals(
// requireNonNull(
// requireNonNull(cacheManager.getCache("configurations")).get(responseEntity.getBody().getId())).get(), configuration, true, StorageConfiguration.class, "metadata"));
}

@Test
Expand All @@ -92,13 +92,13 @@ void canGetConfigurationById() {
ResponseEntity<StorageConfiguration> firstResponse = get(configurationsUrl + configurationDto.getId(), StorageConfiguration.class);
assertThat(firstResponse.getStatusCode(), is(HttpStatus.OK));

// Verify cache
Object cachedConfiguration = requireNonNull(requireNonNull(cacheManager.getCache("configurations")).get(configurationDto.getId())).get();
// Verify cache disable via MODRS-42
// Object cachedConfiguration = requireNonNull(requireNonNull(cacheManager.getCache("configurations")).get(configurationDto.getId())).get();

ResponseEntity<StorageConfiguration> secondResponse = get(configurationsUrl + configurationDto.getId(), StorageConfiguration.class);
assertThat(secondResponse.getStatusCode(), is(HttpStatus.OK));
assertTrue(EqualsBuilder.reflectionEquals(configurationDto, secondResponse.getBody(), true, StorageConfiguration.class, "metadata"));
assertTrue(EqualsBuilder.reflectionEquals(cachedConfiguration, secondResponse.getBody(), true, StorageConfiguration.class, "metadata"));
// assertTrue(EqualsBuilder.reflectionEquals(cachedConfiguration, secondResponse.getBody(), true, StorageConfiguration.class, "metadata"));

}

Expand All @@ -109,10 +109,10 @@ void canPutConfiguration() {
ResponseEntity<String> response = put(configurationsUrl + configurationDto.getId(),configurationDto);
assertThat(response.getStatusCode(), equalTo(HttpStatus.NO_CONTENT));

// Verify caching
// Verify caching disable via MODRS-42
StorageConfiguration configuration = get(configurationsUrl + "/" + configurationDto.getId(), StorageConfiguration.class).getBody();
assertTrue(EqualsBuilder.reflectionEquals(configurationDto, configuration, true, StorageConfiguration.class, "metadata"));
assertTrue(EqualsBuilder.reflectionEquals(requireNonNull(requireNonNull(cacheManager.getCache("configurations")).get(configurationDto.getId())).get(), configuration, true, StorageConfiguration.class, "metadata"));
// assertTrue(EqualsBuilder.reflectionEquals(requireNonNull(requireNonNull(cacheManager.getCache("configurations")).get(configurationDto.getId())).get(), configuration, true, StorageConfiguration.class, "metadata"));

}

Expand Down
19 changes: 10 additions & 9 deletions src/test/java/org/folio/rs/controller/LocationMappingsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ void canPostMapping() {
assertThat(responseEntity.getBody().getFolioLocationId(), notNullValue());
assertThat(responseEntity.getBody().getConfigurationId(), notNullValue());

// Verify caching
// Verify caching disable via MODRS-42
LocationMapping mapping = get(mappingsUrl + "/" + responseEntity.getBody().getFolioLocationId(), LocationMapping.class).getBody();
assertTrue(EqualsBuilder.reflectionEquals(responseEntity.getBody(), mapping, true, StorageConfiguration.class, METADATA));
assertTrue(EqualsBuilder.reflectionEquals(
requireNonNull(
requireNonNull(cacheManager.getCache(MAPPINGS)).get(responseEntity.getBody().getFolioLocationId())).get(), mapping, true, StorageConfiguration.class, METADATA));
// assertTrue(EqualsBuilder.reflectionEquals(
// requireNonNull(
// requireNonNull(cacheManager.getCache(MAPPINGS)).get(responseEntity.getBody().getFolioLocationId())).get(), mapping, true, StorageConfiguration.class, METADATA));

}

Expand All @@ -76,13 +76,13 @@ void canGetMappingById() {
ResponseEntity<LocationMapping> firstResponse = get(mappingsUrl + mapping.getFolioLocationId(), LocationMapping.class);
assertThat(firstResponse.getStatusCode(), is(HttpStatus.OK));

// Verify cache
Object cachedMapping = requireNonNull(requireNonNull(cacheManager.getCache(MAPPINGS)).get(mapping.getFolioLocationId())).get();
// Verify cache disable via MODRS-42
// Object cachedMapping = requireNonNull(requireNonNull(cacheManager.getCache(MAPPINGS)).get(mapping.getFolioLocationId())).get();

ResponseEntity<LocationMapping> secondResponse = get(mappingsUrl + mapping.getFolioLocationId(), LocationMapping.class);
assertThat(secondResponse.getStatusCode(), is(HttpStatus.OK));
assertTrue(EqualsBuilder.reflectionEquals(mapping, secondResponse.getBody(), true, LocationMapping.class, "metadata"));
assertTrue(EqualsBuilder.reflectionEquals(cachedMapping, secondResponse.getBody(), true, LocationMapping.class, "metadata"));
// assertTrue(EqualsBuilder.reflectionEquals(cachedMapping, secondResponse.getBody(), true, LocationMapping.class, "metadata"));
}

@Test
Expand All @@ -92,9 +92,10 @@ void canDeleteMapping() {
.folioLocationId(randomIdAsString())
.configurationId(randomIdAsString()),
LocationMapping.class);
assertThat(requireNonNull(cacheManager.getCache(MAPPINGS)).get(requireNonNull(responseEntity.getBody()).getFolioLocationId()), notNullValue());
// Verify cache disable via MODRS-42
// assertThat(requireNonNull(cacheManager.getCache(MAPPINGS)).get(requireNonNull(responseEntity.getBody()).getFolioLocationId()), notNullValue());
assertThat(delete(mappingsUrl + responseEntity.getBody().getFolioLocationId()).getStatusCode(), is(HttpStatus.NO_CONTENT));
assertThat(requireNonNull(cacheManager.getCache(MAPPINGS)).get(requireNonNull(responseEntity.getBody()).getFolioLocationId()), nullValue());
// assertThat(requireNonNull(cacheManager.getCache(MAPPINGS)).get(requireNonNull(responseEntity.getBody()).getFolioLocationId()), nullValue());
}

@Test
Expand Down

0 comments on commit 83894d3

Please sign in to comment.