Skip to content

Commit

Permalink
re
Browse files Browse the repository at this point in the history
  • Loading branch information
kjain110 committed Sep 9, 2024
1 parent fd3555f commit d7a98cc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/main/java/org/folio/fqm/resource/MigrationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ public ResponseEntity<FqmMigrateResponse> fqmMigrate(FqmMigrateRequest fqmMigrat
.toList());
return new ResponseEntity<>(fqmMigrateResponse, HttpStatus.OK);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import org.folio.fqm.domain.dto.FqmMigrateRequest;
import org.folio.fqm.domain.dto.FqmMigrateResponse;
import org.folio.fqm.domain.dto.FqmMigrateResponseWarningsInner;
import org.folio.fqm.migration.MigratableQueryInformation;
import org.folio.fqm.migration.warnings.DeprecatedEntityWarning;
import org.folio.fqm.migration.warnings.Warning;
Expand Down Expand Up @@ -73,12 +75,16 @@ void shouldMigrateFqmSuccessfully() throws Exception {

when(executionContext.getTenantId()).thenReturn(tenantId);
when(migratableQueryInformation.entityTypeId()).thenReturn(entityTypeID);
when(migratableQueryInformation.fqlQuery()).thenReturn("users.active");
when(migratableQueryInformation.fqlQuery()).thenReturn("users_active");
when(migratableQueryInformation.fields()).thenReturn(List.of("field1", "field2"));
when(migratableQueryInformation.warnings()).thenReturn(warningList);

when(migrationService.migrate(any(MigratableQueryInformation.class))).thenReturn(migratableQueryInformation);
FqmMigrateResponseWarningsInner fqmMigrateResponseWarningsInner = new FqmMigrateResponseWarningsInner().description("abc").type("def");

FqmMigrateResponse fqmMigrateResponse = new FqmMigrateResponse().entityTypeId(migratableQueryInformation.entityTypeId())
.fqlQuery(migratableQueryInformation.fqlQuery())
.warnings(List.of(fqmMigrateResponseWarningsInner));
RequestBuilder builder = MockMvcRequestBuilders
.post(POST_FQM_MIGRATE_REQUEST)
.header(XOkapiHeaders.TENANT, tenantId)
Expand All @@ -90,7 +96,8 @@ void shouldMigrateFqmSuccessfully() throws Exception {
.andExpect(status().isOk())
.andExpect(jsonPath("$.entityTypeId", is(entityTypeID.toString())))
.andExpect(jsonPath("$.fqlQuery", is("users.active")))
.andExpect(jsonPath("$.fields", is(List.of("field1", "field2"))));
.andExpect(jsonPath("$.fields", is(List.of("field1", "field2"))))
.andExpect(jsonPath("$.warnings[0].type", is(fqmMigrateResponse.warnings(List.of(fqmMigrateResponseWarningsInner)))));
}
@NotNull
private static FqmMigrateRequest getFqmMigrateRequest(UUID entityTypeID) {
Expand All @@ -100,4 +107,49 @@ private static FqmMigrateRequest getFqmMigrateRequest(UUID entityTypeID) {
fqmMigrateRequest.setFields(List.of("field1", "field2"));
return fqmMigrateRequest;
}

@Test
void shouldMigrateFqmSuccessfully1() throws Exception {
String tenantId = "tenant_01";
UUID entityTypeID = UUID.randomUUID();
FqmMigrateRequest fqmMigrateRequest = getFqmMigrateRequest(entityTypeID);

MigratableQueryInformation migratableQueryInformation = mock(MigratableQueryInformation.class);

Warning deprecatedEntityWarning = new DeprecatedEntityWarning("abc", "def");
List<Warning> warningList = List.of(deprecatedEntityWarning);

when(executionContext.getTenantId()).thenReturn(tenantId);
when(migratableQueryInformation.entityTypeId()).thenReturn(entityTypeID);
when(migratableQueryInformation.fqlQuery()).thenReturn("users.active");
when(migratableQueryInformation.fields()).thenReturn(List.of("field1", "field2"));
when(migratableQueryInformation.warnings()).thenReturn(warningList);

when(migrationService.migrate(any(MigratableQueryInformation.class))).thenReturn(migratableQueryInformation);
FqmMigrateResponseWarningsInner fqmMigrateResponseWarningsInner = new FqmMigrateResponseWarningsInner()
.description("abc")
.type("DEPRECATED_ENTITY");

FqmMigrateResponse fqmMigrateResponse = new FqmMigrateResponse()
.entityTypeId(migratableQueryInformation.entityTypeId())
.fqlQuery(migratableQueryInformation.fqlQuery())
.fields(migratableQueryInformation.fields())
.warnings(List.of(fqmMigrateResponseWarningsInner));

RequestBuilder builder = MockMvcRequestBuilders
.post(POST_FQM_MIGRATE_REQUEST)
.header(XOkapiHeaders.TENANT, tenantId)
.contentType(APPLICATION_JSON)
.content(new ObjectMapper().writeValueAsString(fqmMigrateRequest));

mockMvc
.perform(builder)
.andExpect(status().isOk())
.andExpect(jsonPath("$.entityTypeId", is(entityTypeID.toString())))
.andExpect(jsonPath("$.fqlQuery", is("users.active")))
.andExpect(jsonPath("$.fields", is(List.of("field1", "field2"))));
// .andExpect(jsonPath("$.warnings[3].type", is("DEPRECATED_ENTITY")))
// .andExpect(jsonPath("$.warnings[2].description", is("abc")));
}

}

0 comments on commit d7a98cc

Please sign in to comment.