Skip to content

Commit

Permalink
test(java): Add integ tests for readAuthorizationModel(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
booniepepper committed Jul 31, 2023
1 parent 426b3d3 commit 17bc284
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion config/clients/java/template/OpenFgaApiIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,52 @@ public void listStores() throws ApiException {
}
}

@Test
public void readAuthModel() throws Exception {
// Given
String storeName = thisTestName();
String storeId = createStore(storeName);
String authModelId = writeAuthModel(storeId);

// When
ReadAuthorizationModelResponse response = api.readAuthorizationModel(storeId, authModelId);

// Then
AuthorizationModel authModel = response.getAuthorizationModel();
assertEquals(authModelId, authModel.getId());
String typeDefsJson = mapper.writeValueAsString(authModel.getTypeDefinitions());
assertEquals(
"[{\"type\":\"user\",\"relations\":{},\"metadata\":null},{\"type\":\"document\",\"relations\":{\"owner\":{\"this\":{},\"computedUserset\":null,\"tupleToUserset\":null,\"union\":null,\"intersection\":null,\"difference\":null},\"reader\":{\"this\":{},\"computedUserset\":null,\"tupleToUserset\":null,\"union\":null,\"intersection\":null,\"difference\":null},\"writer\":{\"this\":{},\"computedUserset\":null,\"tupleToUserset\":null,\"union\":null,\"intersection\":null,\"difference\":null}},\"metadata\":{\"relations\":{\"owner\":{\"directly_related_user_types\":[{\"type\":\"user\",\"relation\":null,\"wildcard\":null}]},\"reader\":{\"directly_related_user_types\":[{\"type\":\"user\",\"relation\":null,\"wildcard\":null}]},\"writer\":{\"directly_related_user_types\":[{\"type\":\"user\",\"relation\":null,\"wildcard\":null}]}}}}]",
typeDefsJson);
}

@Test
public void readAuthModels() throws Exception {
// Given
String storeName = thisTestName();
String storeId = createStore(storeName);
String authModelId = writeAuthModel(storeId);

// When
ReadAuthorizationModelsResponse response = api.readAuthorizationModels(storeId, 100, null);

// Then
response.getAuthorizationModels().stream()
.filter(authModel -> authModel.getId().equals(authModelId))
.forEach(authModel -> {
assertEquals(authModelId, authModel.getId());
try {
String typeDefsJson = mapper.writeValueAsString(authModel.getTypeDefinitions());

assertEquals(
"[{\"type\":\"user\",\"relations\":{},\"metadata\":null},{\"type\":\"document\",\"relations\":{\"owner\":{\"this\":{},\"computedUserset\":null,\"tupleToUserset\":null,\"union\":null,\"intersection\":null,\"difference\":null},\"reader\":{\"this\":{},\"computedUserset\":null,\"tupleToUserset\":null,\"union\":null,\"intersection\":null,\"difference\":null},\"writer\":{\"this\":{},\"computedUserset\":null,\"tupleToUserset\":null,\"union\":null,\"intersection\":null,\"difference\":null}},\"metadata\":{\"relations\":{\"owner\":{\"directly_related_user_types\":[{\"type\":\"user\",\"relation\":null,\"wildcard\":null}]},\"reader\":{\"directly_related_user_types\":[{\"type\":\"user\",\"relation\":null,\"wildcard\":null}]},\"writer\":{\"directly_related_user_types\":[{\"type\":\"user\",\"relation\":null,\"wildcard\":null}]}}}}]",
typeDefsJson);
} catch (JsonProcessingException ex) {
assertNull(ex);
}
});
}

@Test
public void writeAuthModel() throws ApiException, JsonProcessingException {
// Given
Expand Down Expand Up @@ -159,7 +205,7 @@ public void write_and_check() throws Exception {
.relation("reader")
._object(DEFAULT_DOC))));
CheckRequest checkRequest =
new CheckRequest().tupleKey(new TupleKey().user(DEFAULT_USER)._object(DEFAULT_DOC));
new CheckRequest().tupleKey(new TupleKey().user(DEFAULT_USER).relation("reader")._object(DEFAULT_DOC));

// When
api.write(storeId, writeRequest);
Expand Down

0 comments on commit 17bc284

Please sign in to comment.