src_fm_fc_ms_ff
stringlengths
43
86.8k
target
stringlengths
20
276k
NestedPatch extends AbstractNestedMutateOperation implements OASOperation { @Override public OperationType operationType() { return operationType; } NestedPatch(MetaResource metaResource, MetaResourceField metaResourceField, MetaResource relatedMetaResource); @Override OperationType operationType(); @Override boolean i...
@Test void operationType() { NestedPatch NestedPatch = new NestedPatch(metaResource, metaResourceField, relatedMetaResource); Assert.assertEquals(OperationType.PATCH, NestedPatch.operationType()); }
NestedPatch extends AbstractNestedMutateOperation implements OASOperation { @Override public boolean isEnabled() { return metaResource.isReadable() && metaResourceField.isUpdatable(); } NestedPatch(MetaResource metaResource, MetaResourceField metaResourceField, MetaResource relatedMetaResource); @Override OperationType...
@Test void isEnabledTrueWhenReadableAndFieldUpdatable() { NestedPatch NestedPatch = new NestedPatch(metaResource, metaResourceField, relatedMetaResource); Assert.assertTrue(metaResource.isReadable()); metaResourceField.setUpdatable(true); Assert.assertTrue(NestedPatch.isEnabled()); } @Test void isEnabledFalseWhenReadab...
NestedPatch extends AbstractNestedMutateOperation implements OASOperation { @Override public String getDescription() { return "Update " + metaResource.getResourceType() + " relationship to a " + relatedMetaResource.getResourceType() + " resource"; } NestedPatch(MetaResource metaResource, MetaResourceField metaResourceF...
@Test void getDescription() { NestedPatch NestedPatch = new NestedPatch(metaResource, metaResourceField, relatedMetaResource); Assert.assertEquals("Update ResourceType relationship to a RelatedResourceType resource", NestedPatch.getDescription()); }
NestedPatch extends AbstractNestedMutateOperation implements OASOperation { @Override public Operation operation() { Operation operation = super.operation(); ApiResponse responseSchema = OASUtils.oneToMany(metaResourceField) ? new ResourceReferencesResponse(relatedMetaResource).$ref() : new ResourceReferenceResponse(re...
@Test void operation() { Operation operation = new NestedPatch(metaResource, metaResourceField, relatedMetaResource).operation(); Assert.assertTrue(operation.getResponses().containsKey("200")); }
NestedPatch extends AbstractNestedMutateOperation implements OASOperation { @Override public String path() { return OASUtils.getNestedPath(metaResource, metaResourceField); } NestedPatch(MetaResource metaResource, MetaResourceField metaResourceField, MetaResource relatedMetaResource); @Override OperationType operationT...
@Test void path() { NestedPatch NestedPatch = new NestedPatch(metaResource, metaResourceField, relatedMetaResource); Assert.assertEquals("/ResourcePath/{id}/someRelatedResource", NestedPatch.path()); }
RelationshipPatch extends AbstractNestedMutateOperation implements OASOperation { @Override public OperationType operationType() { return operationType; } RelationshipPatch(MetaResource metaResource, MetaResourceField metaResourceField, MetaResource relatedMetaResource); @Override OperationType operationType(); @Overri...
@Test void operationType() { RelationshipPatch RelationshipPatch = new RelationshipPatch(metaResource, metaResourceField, relatedMetaResource); Assert.assertEquals(OperationType.PATCH, RelationshipPatch.operationType()); }
RelationshipPatch extends AbstractNestedMutateOperation implements OASOperation { @Override public boolean isEnabled() { return metaResource.isReadable() && metaResourceField.isUpdatable(); } RelationshipPatch(MetaResource metaResource, MetaResourceField metaResourceField, MetaResource relatedMetaResource); @Override O...
@Test void isEnabledTrueWhenReadableAndFieldUpdatable() { RelationshipPatch RelationshipPatch = new RelationshipPatch(metaResource, metaResourceField, relatedMetaResource); Assert.assertTrue(metaResource.isReadable()); metaResourceField.setUpdatable(true); Assert.assertTrue(RelationshipPatch.isEnabled()); } @Test void ...
RelationshipPatch extends AbstractNestedMutateOperation implements OASOperation { @Override public String getDescription() { return "Update " + metaResource.getResourceType() + " relationship to a " + relatedMetaResource.getResourceType() + " resource"; } RelationshipPatch(MetaResource metaResource, MetaResourceField m...
@Test void getDescription() { RelationshipPatch RelationshipPatch = new RelationshipPatch(metaResource, metaResourceField, relatedMetaResource); Assert.assertEquals("Update ResourceType relationship to a RelatedResourceType resource", RelationshipPatch.getDescription()); }
RelationshipPatch extends AbstractNestedMutateOperation implements OASOperation { @Override public Operation operation() { Operation operation = super.operation(); ApiResponse responseSchema = OASUtils.oneToMany(metaResourceField) ? new ResourceReferencesResponse(relatedMetaResource).$ref() : new ResourceReferenceRespo...
@Test void operation() { Operation operation = new RelationshipPatch(metaResource, metaResourceField, relatedMetaResource).operation(); Assert.assertTrue(operation.getResponses().containsKey("200")); }
RelationshipPatch extends AbstractNestedMutateOperation implements OASOperation { @Override public String path() { return OASUtils.getRelationshipsPath(metaResource, metaResourceField); } RelationshipPatch(MetaResource metaResource, MetaResourceField metaResourceField, MetaResource relatedMetaResource); @Override Opera...
@Test void path() { RelationshipPatch RelationshipPatch = new RelationshipPatch(metaResource, metaResourceField, relatedMetaResource); Assert.assertEquals("/ResourcePath/{id}/relationships/someRelatedResource", RelationshipPatch.path()); }
OASGenerator { @VisibleForTesting static String generateOpenApiContent(OpenAPI openApi, OutputFormat outputFormat, Boolean sort) { if (sort) { ObjectMapper objectMapper = outputFormat.mapper(); objectMapper.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS); objectMapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABE...
@Test public void testGenerateOpenApiContentGeneratesYamlUnsorted() throws IOException { compare( "gold/unsorted.yaml", OASGenerator.generateOpenApiContent(openApi, OutputFormat.YAML, false)); } @Test public void testGenerateOpenApiContentGeneratesYamlSorted() throws IOException { compare( "gold/sorted.yaml", OASGenera...
ResourceReferencesResponseSchema extends AbstractSchemaGenerator { public Schema schema() { return new ObjectSchema() .addProperties( "data", new ArraySchema() .items(new ResourceReference(metaResource).$ref())); } ResourceReferencesResponseSchema(MetaResource metaResource); Schema schema(); }
@Test void schema() { Schema schema = new ResourceReferencesResponseSchema(metaResource).schema(); Assert.assertTrue(schema instanceof ObjectSchema); Assert.assertTrue(schema.getProperties().containsKey("data")); Assert.assertEquals(1, schema.getProperties().size()); Schema data = (Schema) schema.getProperties().get("d...
TypeSchema extends AbstractSchemaGenerator { public Schema schema() { Schema typeSchema = new StringSchema() .description("The JSON:API resource type (" + metaResource.getResourceType() + ")"); typeSchema.addEnumItemObject(metaResource.getResourceType()); return typeSchema; } TypeSchema(MetaResource metaResource); Sche...
@Test void schema() { final Schema typeSchema = new TypeSchema(metaResource).schema(); assertNotNull(typeSchema); assertEquals(StringSchema.class, typeSchema.getClass()); assertIterableEquals(singletonList("ResourceType"), typeSchema.getEnum()); }
ApiError extends AbstractSchemaGenerator { public Schema schema() { return new ObjectSchema() .addProperties( "id", new StringSchema() .description("a unique identifier for this particular occurrence of the problem")) .addProperties("links", new ObjectSchema() .addProperties( "about", new StringSchema() .description("a...
@Test void schema() { Schema schema = new ApiError().schema(); Assert.assertTrue(schema instanceof ObjectSchema); Assert.assertTrue(schema.getProperties().containsKey("id")); Assert.assertTrue(schema.getProperties().containsKey("links")); Assert.assertTrue(schema.getProperties().containsKey("status")); Assert.assertTru...
ResourceReferenceResponseSchema extends AbstractSchemaGenerator { public Schema schema() { return new ObjectSchema() .addProperties( "data", new ResourceReference(metaResource).$ref()); } ResourceReferenceResponseSchema(MetaResource metaResource); Schema schema(); }
@Test void schema() { Schema schema = new ResourceReferenceResponseSchema(metaResource).schema(); Assert.assertTrue(schema instanceof ObjectSchema); Assert.assertTrue(schema.getProperties().containsKey("data")); Assert.assertEquals(1, schema.getProperties().size()); Schema data = (Schema) schema.getProperties().get("da...
PostResourceData extends AbstractSchemaGenerator { @Override public Schema schema() { return new ComposedSchema().allOf( OASUtils.getIncludedSchemaRefs( new PostResourceReference(metaResource), new ResourcePostAttributes(metaResource), new ResourcePostRelationships(metaResource) )); } PostResourceData(MetaResource meta...
@Test public void schema() { additionalMetaResourceField.setInsertable(true); final Schema dataSchema = new PostResourceData(metaResource).schema(); assertNotNull(dataSchema); assertEquals(ComposedSchema.class, dataSchema.getClass()); final List<Schema> allOf = ((ComposedSchema) dataSchema).getAllOf(); assertNotNull(al...
PostResources extends AbstractSchemaGenerator { @Override public Schema schema() { return new ObjectSchema() .addRequiredItem("data") .addProperties("data", new ArraySchema() .items(new PostResourceData(metaResource).$ref())); } PostResources(MetaResource metaResource); @Override Schema schema(); }
@Test void schema() { Schema requestSchema = new PostResources(metaResource).schema(); assertNotNull(requestSchema); assertEquals(ObjectSchema.class, requestSchema.getClass()); ObjectSchema topLevelSchema = (ObjectSchema) requestSchema; assertIterableEquals(singleton("data"), topLevelSchema.getProperties().keySet()); S...
Links extends AbstractSchemaGenerator { public Schema schema() { return new ComposedSchema() .allOf( Arrays.asList( new ObjectSchema() .additionalProperties( new Link().$ref()), new Pagination().$ref() )) .description("Link members related to the primary data."); } Schema schema(); }
@Test void schema() { Schema schema = new Links().schema(); Assert.assertTrue(schema instanceof ComposedSchema); List<Schema> allOf = ((ComposedSchema) schema).getAllOf(); Assert.assertEquals(2, allOf.size()); Assert.assertTrue(allOf.get(0) instanceof ObjectSchema); Assert.assertEquals(new Pagination().$ref().get$ref()...
ResourceRelationships extends AbstractResourceAttributes { @Override public Schema schema() { return super.schema() .description("Relationships between the resource and other JSON:API resources"); } ResourceRelationships(MetaResource metaResource); @Override Schema schema(); }
@Test void schema() { Schema schema = new ResourceRelationships(metaResource).schema(); assertNotNull(schema); assertEquals(ObjectSchema.class, schema.getClass()); assertIterableEquals(singleton("relationships"), schema.getProperties().keySet()); Schema relationshipsSchema = ((ObjectSchema) schema).getProperties().get(...
PatchResource extends AbstractSchemaGenerator { @Override public Schema schema() { return new ObjectSchema() .addRequiredItem("data") .addProperties("data", new ComposedSchema().allOf( OASUtils.getIncludedSchemaRefs( new ResourceReference(metaResource), new ResourcePatchAttributes(metaResource), new ResourcePatchRelati...
@Test void schema() { relationshipMetaResourceField.setUpdatable(true); Schema requestSchema = new PatchResource(metaResource).schema(); ObjectSchema topLevelSchema = (ObjectSchema) requestSchema; assertIterableEquals(singleton("data"), topLevelSchema.getProperties().keySet()); Schema dataSchema = topLevelSchema.getPro...
PostResourceReference extends AbstractSchemaGenerator { public Schema schema() { MetaAttribute metaAttribute = getPrimaryKeyMetaResourceField(metaResource); return new ObjectSchema() .addProperties( "type", new TypeSchema(metaResource).schema()) .addProperties( "id", new ResourceAttribute(metaResource, metaAttribute).$...
@Test void schema() { Schema schema = new PostResourceReference(metaResource).schema(); Assert.assertTrue(schema instanceof ObjectSchema); Assert.assertTrue(schema.getProperties().containsKey("type")); Assert.assertTrue(schema.getProperties().containsKey("id")); Assert.assertEquals(2, schema.getProperties().size()); As...
Info extends AbstractSchemaGenerator { public Schema schema() { return new ObjectSchema() .addProperties("jsonapi", new JsonApi().$ref()) .addProperties( "meta", new Meta().$ref()) .addProperties( "links", new Links().$ref()) .required(Collections.singletonList("meta")) .additionalProperties(false); } Schema schema();...
@Test void schema() { Schema schema = new Info().schema(); Assert.assertTrue(schema instanceof ObjectSchema); Assert.assertTrue(schema.getProperties().containsKey("jsonapi")); Assert.assertTrue(schema.getProperties().containsKey("links")); Assert.assertTrue(schema.getProperties().containsKey("meta")); Assert.assertEqua...
ResourceAttribute extends AbstractSchemaGenerator { public Schema schema() { Schema schema = OASUtils.transformMetaResourceField(metaAttribute.getType()); if (metaAttribute.isPrimaryKeyAttribute()) { schema.setDescription("The JSON:API resource ID"); } schema.nullable(metaAttribute.isNullable()); OASAnnotations.getInst...
@Test void schemaPrimaryKey() { MetaResource metaResource = getTestMetaResource(); MetaResourceField metaResourceField = (MetaResourceField) metaResource.getChildren().get(0); Schema schema = new ResourceAttribute(metaResource, metaResourceField).schema(); Assert.assertTrue(schema instanceof StringSchema); Assert.asser...
Meta extends AbstractSchemaGenerator { public Schema schema() { return new ObjectSchema() .description("Non-standard meta-information that can not be represented as an attribute or relationship.") .additionalProperties(true); } Schema schema(); }
@Test void schema() { Schema schema = new Meta().schema(); Assert.assertTrue(schema instanceof ObjectSchema); Assert.assertTrue((boolean) schema.getAdditionalProperties()); Assert.assertNull(schema.getProperties()); }
Link extends AbstractSchemaGenerator { public Schema schema() { return new ComposedSchema() .oneOf( Arrays.asList( new StringSchema() .description("A string containing the link's URL.") .format("uri"), new ObjectSchema() .required(Collections.singletonList("href")) .addProperties( "href", new StringSchema() .format("ur...
@Test void schema() { Schema schema = new Link().schema(); Assert.assertTrue(schema instanceof ComposedSchema); List<Schema> oneOf = ((ComposedSchema) schema).getOneOf(); Assert.assertEquals(2, oneOf.size()); StringSchema stringSchema = (StringSchema) oneOf.get(0); Assert.assertEquals("uri", stringSchema.getFormat()); ...
ResourceReference extends AbstractSchemaGenerator { public Schema schema() { return new PostResourceReference(metaResource) .schema() .required(Arrays.asList("id", "type")); } ResourceReference(MetaResource metaResource); Schema schema(); }
@Test void schema() { Schema schema = new ResourceReference(metaResource).schema(); Assert.assertTrue(schema instanceof ObjectSchema); Assert.assertTrue(schema.getProperties().containsKey("id")); Assert.assertTrue(schema.getProperties().containsKey("type")); Assert.assertEquals(2, schema.getProperties().size()); Assert...
PostResource extends AbstractSchemaGenerator { @Override public Schema schema() { return new ObjectSchema() .addRequiredItem("data") .addProperties("data", new PostResourceData(metaResource).$ref()); } PostResource(MetaResource metaResource); @Override Schema schema(); }
@Test void schema() { Schema requestSchema = new PostResource(metaResource).schema(); assertNotNull(requestSchema); assertEquals(ObjectSchema.class, requestSchema.getClass()); ObjectSchema topLevelSchema = (ObjectSchema) requestSchema; assertIterableEquals(singleton("data"), topLevelSchema.getProperties().keySet()); Sc...
ResourceSchema extends AbstractSchemaGenerator { public Schema schema() { return new ComposedSchema().allOf( OASUtils.getIncludedSchemaRefs( new ResourceReference(metaResource), new ResourceAttributes(metaResource), new ResourceRelationships(metaResource), new ResourceLinks(metaResource) )).addRequiredItem("attributes"...
@Test void schema() { Schema resourceSchema = new ResourceSchema(metaResource).schema(); assertNotNull(resourceSchema); assertEquals(ComposedSchema.class, resourceSchema.getClass()); assertIterableEquals(singletonList("attributes"), resourceSchema.getRequired()); List<Schema> allOf = ((ComposedSchema) resourceSchema).g...
Success extends AbstractSchemaGenerator { public Schema schema() { return new ObjectSchema() .description("A JSON:API document with a single resource") .addProperties("jsonapi", new JsonApi().$ref()) .addProperties( "included", new ArraySchema() .items( new ObjectSchema() .addProperties( "type", new StringSchema() .des...
@Test void schema() { Schema schema = new Success().schema(); Assert.assertTrue(schema instanceof ObjectSchema); Assert.assertTrue(schema.getProperties().containsKey("jsonapi")); Assert.assertTrue(schema.getProperties().containsKey("links")); Assert.assertTrue(schema.getProperties().containsKey("meta")); Assert.assertT...
ResourceResponseSchema extends AbstractSchemaGenerator { public Schema schema() { return new ComposedSchema() .allOf( Arrays.asList( new Success().$ref(), new Schema() .addProperties( "data", new ResourceSchema(metaResource).$ref()) .required(Collections.singletonList("data")))); } ResourceResponseSchema(MetaResource m...
@Test void schema() { Schema schema = new ResourceResponseSchema(metaResource).schema(); Assert.assertTrue(schema instanceof ComposedSchema); List<Schema> allOf = ((ComposedSchema) schema).getAllOf(); Assert.assertEquals(2, allOf.size()); Assert.assertEquals("#/components/schemas/Success", allOf.get(0).get$ref()); Sche...
ResourcesResponseSchema extends AbstractSchemaGenerator { public Schema schema() { return new ComposedSchema() .allOf( Arrays.asList( new Success().$ref(), new Schema() .addProperties( "data", new ArraySchema() .items(new ResourceSchema(metaResource).$ref())) .required(Collections.singletonList("data")))); } ResourcesR...
@Test void schema() { Schema schema = new ResourcesResponseSchema(metaResource).schema(); Assert.assertTrue(schema instanceof ComposedSchema); List<Schema> allOf = ((ComposedSchema) schema).getAllOf(); Assert.assertEquals(2, allOf.size()); Assert.assertEquals("#/components/schemas/Success", allOf.get(0).get$ref()); Sch...
ResourcePermission { @Override public boolean equals(Object obj) { if (obj != null && obj.getClass() == ResourcePermission.class) { ResourcePermission p = (ResourcePermission) obj; return p.deleteAllowed == deleteAllowed && p.getAllowed == getAllowed && p.patchAllowed == patchAllowed && p.postAllowed == postAllowed; } ...
@Test public void testEquals() { EqualsVerifier.forClass(ResourceIdentifier.class).usingGetClass().suppress(Warning.NONFINAL_FIELDS).verify(); Assert.assertEquals(ResourcePermission.ALL, ResourcePermission.ALL); Assert.assertEquals(ResourcePermission.DELETE, ResourcePermission.DELETE); Assert.assertEquals(ResourcePermi...
JsonApi extends AbstractSchemaGenerator { public Schema schema() { return new ObjectSchema() .addProperties( "version", new StringSchema()) .additionalProperties(false); } Schema schema(); }
@Test void schema() { Schema schema = new JsonApi().schema(); Assert.assertTrue(schema instanceof ObjectSchema); Assert.assertTrue(schema.getProperties().containsKey("version")); Assert.assertEquals(1, schema.getProperties().size()); }
Failure extends AbstractSchemaGenerator { public Schema schema() { return new ObjectSchema() .addProperties("jsonapi", new JsonApi().$ref()) .addProperties( "errors", new ArraySchema() .items(new ApiError().$ref()) .uniqueItems(true)) .addProperties( "meta", new Meta().$ref()) .addProperties( "links", new Links().$ref(...
@Test void schema() { Schema schema = new Failure().schema(); Assert.assertTrue(schema instanceof ObjectSchema); Assert.assertTrue(schema.getProperties().containsKey("jsonapi")); Assert.assertTrue(schema.getProperties().containsKey("errors")); Assert.assertTrue(schema.getProperties().containsKey("links")); Assert.asser...
Pagination extends AbstractSchemaGenerator { public Schema schema() { return new ObjectSchema() .addProperties( "first", new StringSchema() .description("The first page of data") .format("uri") .nullable(true)) .addProperties( "last", new StringSchema() .description("The last page of data") .format("uri") .nullable(tru...
@Test void schema() { Schema schema = new Pagination().schema(); Assert.assertTrue(schema instanceof ObjectSchema); Stream.of("first", "last", "prev", "next").forEach( key -> { Schema subSchema = (Schema) schema.getProperties().get(key); Assert.assertTrue(subSchema instanceof StringSchema); Assert.assertTrue(subSchema....
ResourceReferencesResponse extends AbstractResponseGenerator { public ApiResponse response() { return new ApiResponse() .description(HttpStatus.toMessage(200)) .content( new Content() .addMediaType( "application/vnd.api+json", new MediaType() .schema(new ResourceReferencesResponseSchema(metaResource).$ref()))); } Resou...
@Test void response() { ApiResponse apiResponse = new ResourceReferencesResponse(metaResource).response(); Assert.assertNotNull(apiResponse); Assert.assertEquals("OK", apiResponse.getDescription()); Content content = apiResponse.getContent(); Assert.assertEquals(1, content.size()); Schema schema = content.get("applicat...
NoContent extends AbstractResponseGenerator { public ApiResponse response() { return new ApiResponse() .description("No Content"); } ApiResponse response(); }
@Test void response() { ApiResponse apiResponse = new NoContent().response(); Assert.assertEquals("No Content", apiResponse.getDescription()); Assert.assertNull(apiResponse.getContent()); }
ResourceResponse extends AbstractResponseGenerator { public ApiResponse response() { return new ApiResponse() .description(HttpStatus.toMessage(200)) .content( new Content() .addMediaType( "application/vnd.api+json", new MediaType() .schema(new ResourceResponseSchema(metaResource).$ref()))); } ResourceResponse(MetaReso...
@Test void response() { ApiResponse apiResponse = new ResourceResponse(metaResource).response(); Assert.assertNotNull(apiResponse); Assert.assertEquals("OK", apiResponse.getDescription()); Content content = apiResponse.getContent(); Assert.assertEquals(1, content.size()); Schema schema = content.get("application/vnd.ap...
StaticResponses { public static Map<String, ApiResponse> generateStandardApiResponses() { return OASMergeUtil.mergeApiResponses(generateStandardApiSuccessResponses(), OASErrors.generateStandardApiErrorResponses()); } static Map<String, ApiResponse> generateStandardApiResponses(); }
@Test void generateStandardApiResponses() { Map<String, ApiResponse> apiResponseMap = StaticResponses.generateStandardApiResponses(); Assert.assertEquals(16, apiResponseMap.size()); Assert.assertNotNull(apiResponseMap.get("NoContent")); Assert.assertNotNull(apiResponseMap.get("400")); Assert.assertNotNull(apiResponseMa...
ResourcesResponse extends AbstractResponseGenerator { public ApiResponse response() { return new ApiResponse() .description(HttpStatus.toMessage(200)) .content( new Content() .addMediaType( "application/vnd.api+json", new MediaType() .schema(new ResourcesResponseSchema(metaResource).$ref()))); } ResourcesResponse(MetaR...
@Test void response() { ApiResponse apiResponse = new ResourcesResponse(metaResource).response(); Assert.assertNotNull(apiResponse); Assert.assertEquals("OK", apiResponse.getDescription()); Content content = apiResponse.getContent(); Assert.assertEquals(1, content.size()); Schema schema = content.get("application/vnd.a...
ResourceReferenceResponse extends AbstractResponseGenerator { public ApiResponse response() { return new ApiResponse() .description(HttpStatus.toMessage(200)) .content( new Content() .addMediaType( "application/vnd.api+json", new MediaType() .schema(new ResourceReferenceResponseSchema(metaResource).$ref()))); } Resourc...
@Test void response() { ApiResponse apiResponse = new ResourceReferenceResponse(metaResource).response(); Assert.assertNotNull(apiResponse); Assert.assertEquals("OK", apiResponse.getDescription()); Content content = apiResponse.getContent(); Assert.assertEquals(1, content.size()); Schema schema = content.get("applicati...
OASMergeUtil { public static Operation mergeOperations(Operation thisOperation, Operation thatOperation) { if (thatOperation == null) { return thisOperation; } if (thatOperation.getTags() != null) { thisOperation.setTags( mergeTags(thisOperation.getTags(), thatOperation.getTags()) ); } if (thatOperation.getExternalDocs...
@Test public void testMergeOperations() { Operation thatOperation = new Operation(); Operation thisOperation = new Operation(); thisOperation.setOperationId("new id"); thisOperation.setSummary("new summary"); thisOperation.setDescription("new description"); Map<String, Object> extensions = new HashMap<>(); extensions.p...
MetaAttributePath implements Iterable<MetaAttribute> { public MetaAttributePath concat(MetaAttribute... pathElements) { ArrayList<MetaAttribute> list = new ArrayList<>(); list.addAll(Arrays.asList(this.pathElements)); list.addAll(Arrays.asList(pathElements)); return to(list.toArray(newArray(0))); } MetaAttributePath(Li...
@Test public void concat() { MetaAttribute attr3 = Mockito.mock(MetaAttribute.class); Mockito.when(attr3.getName()).thenReturn("c"); Assert.assertEquals("a.b.c", path.concat(attr3).toString()); }
NestedFilter extends AbstractParameterGenerator { public Parameter parameter() { return new Parameter() .name("filter") .description("Customizable query (experimental)") .in("query") .schema( new ObjectSchema() .addProperties( "AND", new ObjectSchema() .additionalProperties(true) .nullable(true)) .addProperties( "OR", ...
@Test void parameter() { Parameter parameter = new NestedFilter().parameter(); Assert.assertEquals("filter", parameter.getName()); Assert.assertEquals("query", parameter.getIn()); Assert.assertEquals("Customizable query (experimental)", parameter.getDescription()); Assert.assertNull(parameter.getRequired()); Schema sch...
PrimaryKey extends AbstractParameterGenerator { public Parameter parameter() { MetaResourceField metaResourceField = OASUtils.getPrimaryKeyMetaResourceField(metaResource); return new Parameter() .name(metaResourceField.getName()) .in("path") .schema(new ResourceAttribute(metaResource, metaResourceField).$ref()); } Prim...
@Test void parameter() { Parameter parameter = new PrimaryKey(metaResource).parameter(); Assert.assertEquals("id", parameter.getName()); Assert.assertEquals("path", parameter.getIn()); Assert.assertTrue(parameter.getRequired()); Schema schema = parameter.getSchema(); Assert.assertEquals( "#/components/schemas/ResourceT...
FieldFilter extends AbstractParameterGenerator { public Parameter parameter() { return new Parameter() .name("filter[" + metaResourceField.getName() + "]") .description("Filter by " + metaResourceField.getName() + " (csv)") .in("query") .schema(new StringSchema()); } FieldFilter(MetaResource metaResource, MetaResourceF...
@Test void parameter() { Parameter parameter = new FieldFilter(metaResource, metaResourceField).parameter(); Assert.assertEquals("filter[id]", parameter.getName()); Assert.assertEquals("query", parameter.getIn()); Assert.assertEquals("Filter by id (csv)", parameter.getDescription()); Assert.assertNull(parameter.getRequ...
Fields extends AbstractParameterGenerator { public Parameter parameter() { return new Parameter() .name("fields") .description(metaResource.getResourceType() + " fields to include (csv)") .in("query") .schema(new StringSchema() ._default( OASUtils.attributes(metaResource, true) .map(MetaElement::getName) .collect(joini...
@Test void parameter() { Parameter parameter = new Fields(metaResource).parameter(); Assert.assertEquals("fields", parameter.getName()); Assert.assertEquals("query", parameter.getIn()); Assert.assertEquals("ResourceType fields to include (csv)", parameter.getDescription()); Assert.assertNull(parameter.getRequired()); S...
Include extends AbstractParameterGenerator { public Parameter parameter() { return new Parameter() .name("include") .description(metaResource.getResourceType() + " relationships to include (csv)") .in("query") .schema(new StringSchema() ._default( metaResource .getAttributes() .stream() .filter(MetaAttribute::isAssocia...
@Test void parameter() { Parameter parameter = new Include(metaResource).parameter(); Assert.assertEquals("include", parameter.getName()); Assert.assertEquals("query", parameter.getIn()); Assert.assertEquals("ResourceType relationships to include (csv)", parameter.getDescription()); Assert.assertNull(parameter.getRequi...
Sort extends AbstractParameterGenerator { public Parameter parameter() { return new Parameter() .name("sort") .description(metaResource.getResourceType() + " sort order (csv)") .in("query") .schema(new StringSchema() .example( OASUtils.sortAttributes(metaResource, true) .map(MetaElement::getName) .collect(joining(","))...
@Test void parameterNoSortableAttributes() { MetaResource metaResource = getTestMetaResource(); MetaResourceField metaResourceField = (MetaResourceField) metaResource.getChildren().get(0); MetaResourceField additionalMetaResourceField = (MetaResourceField) metaResource.getChildren().get(1); metaResourceField.setSortabl...
OASErrors { public static Map<String, ApiResponse> generateStandardApiErrorResponses() { Map<String, ApiResponse> responses = new LinkedHashMap<>(); List<Integer> responseCodes = getStandardHttpStatusCodes(); for (Integer responseCode : responseCodes) { if (responseCode >= 400 && responseCode <= 599) { ApiResponse apiR...
@Test public void test() { Map<String, ApiResponse> apiResponseCodes = OASErrors.generateStandardApiErrorResponses(); for (Map.Entry<String, ApiResponse> entry : apiResponseCodes.entrySet()) { Assert.assertTrue(entry.getKey().startsWith("4") || entry.getKey().startsWith("5")); ApiResponse apiResponse = entry.getValue()...
TSFunction extends TSMember implements TSExportedElement { @Override public boolean isField() { return false; } @Override void accept(TSVisitor visitor); List<String> getStatements(); List<TSParameter> getParameters(); void setExported(boolean exported); @Override boolean isExported(); void addParameter(TSParameter pa...
@Test public void notAField() { TSFunction function = new TSFunction(); Assert.assertFalse(function.isField()); }
MetaAttributePath implements Iterable<MetaAttribute> { @Override public String toString() { return render(PATH_SEPARATOR); } MetaAttributePath(List<? extends MetaAttribute> pathElements); MetaAttributePath(MetaAttribute... pathElements); MetaAttributePath subPath(int startIndex); MetaAttributePath subPath(int startInd...
@Test public void toStringForEmptyPath() { Assert.assertEquals("", MetaAttributePath.EMPTY_PATH.toString()); } @Test public void toStringForSingleAttributePath() { MetaAttribute attr3 = Mockito.mock(MetaAttribute.class); Mockito.when(attr3.getName()).thenReturn("c"); path = new MetaAttributePath(Arrays.asList(attr3)); ...
TSFunction extends TSMember implements TSExportedElement { @Override public TSField asField() { throw new UnsupportedOperationException(); } @Override void accept(TSVisitor visitor); List<String> getStatements(); List<TSParameter> getParameters(); void setExported(boolean exported); @Override boolean isExported(); voi...
@Test(expected = UnsupportedOperationException.class) public void cannotCastToField() { TSFunction function = new TSFunction(); function.asField(); }
TSGenerator { protected TSMetaTransformationContext createMetaTransformationContext() { return new TSMetaTransformationContextImpl(); } TSGenerator(File outputDir, MetaLookup lookup, TSGeneratorConfig config); void run(); void transformMetaToTypescript(); void runProcessors(); }
@Test(expected = UnsupportedOperationException.class) public void throwExceptionWhenMetaElementNotMappedToNpmPackage() { TSMetaTransformationContext transformationContext = generator.createMetaTransformationContext(); MetaElement metaElement = Mockito.mock(MetaElement.class); metaElement.setId("does.not.exist"); transf...
TSGenerator { protected TSElement transform(MetaElement element, TSMetaTransformationOptions options) { if (elementSourceMap.containsKey(element)) { return elementSourceMap.get(element); } if (postProcessing) { throw new IllegalStateException("cannot add further element while post processing: " + element.getId()); } fo...
@Test(expected = IllegalStateException.class) public void throwExceptionWhenTransformingUnknownMetaElement() { MetaElement metaElement = Mockito.mock(MetaElement.class); metaElement.setId("does.not.exist"); TSMetaTransformationOptions options = Mockito.mock(TSMetaTransformationOptions.class); generator.transform(metaEl...
TSImportProcessor implements TSSourceProcessor { @Override public List<TSSource> process(List<TSSource> sources) { for (TSSource source : sources) { transform(source); sortImports(source); } return sources; } @Override List<TSSource> process(List<TSSource> sources); }
@Test public void sameDirectoryImport() { List<TSSource> updatedSources = processor.process(sources); Assert.assertEquals(sources.size(), updatedSources.size()); Assert.assertEquals(1, classSource.getImports().size()); TSImport tsImport = classSource.getImports().get(0); Assert.assertEquals("./some-interface", tsImport...
MetaAttributePath implements Iterable<MetaAttribute> { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + Arrays.hashCode(pathElements); return result; } MetaAttributePath(List<? extends MetaAttribute> pathElements); MetaAttributePath(MetaAttribute... pathElements); MetaA...
@Test public void testHashCode() { MetaAttribute attr3 = Mockito.mock(MetaAttribute.class); Mockito.when(attr3.getName()).thenReturn("c"); MetaAttributePath path2 = new MetaAttributePath(Arrays.asList(attr3)); MetaAttributePath path3 = new MetaAttributePath(Arrays.asList(attr3)); Assert.assertNotEquals(path2.hashCode()...
UIModule implements Module { @Override public void setupModule(ModuleContext context) { this.context = context; if(config.isBrowserEnabled()) { context.addHttpRequestProcessor(new UIHttpRequestProcessor(config)); setupHomeExtension(context); } if (config != null && config.isPresentationModelEnabled()) { Supplier<List<P...
@Test public void testDisableBrowser() { UIModuleConfig config = new UIModuleConfig(); config.setBrowserEnabled(false); UIModule module = new UIModule(config); ModuleRegistry moduleRegistry = Mockito.mock(ModuleRegistry.class); Module.ModuleContext context = Mockito.mock(Module.ModuleContext.class); Mockito.when(contex...
UIModule implements Module { public static UIModule create(UIModuleConfig config) { return new UIModule(config); } protected UIModule(); protected UIModule(UIModuleConfig config); static UIModule create(UIModuleConfig config); String getModuleName(); @Override void setupModule(ModuleContext context); PresentationMana...
@Test public void checkHomeModuleExtension() { HomeModule homeModule = HomeModule.create(); UIModule uiModule = UIModule.create(new UIModuleConfig()); CrnkBoot boot = new CrnkBoot(); boot.addModule(homeModule); boot.addModule(uiModule); boot.boot(); List<String> list = homeModule.list("/", new QueryContext()); Assert.a...
MetaAttributePath implements Iterable<MetaAttribute> { public int length() { return pathElements.length; } MetaAttributePath(List<? extends MetaAttribute> pathElements); MetaAttributePath(MetaAttribute... pathElements); MetaAttributePath subPath(int startIndex); MetaAttributePath subPath(int startIndex, int endIndex);...
@Test public void length() { Assert.assertEquals(2, path.length()); }
MetaAttributePath implements Iterable<MetaAttribute> { public MetaAttribute getLast() { if (pathElements != null && pathElements.length > 0) { return pathElements[pathElements.length - 1]; } return null; } MetaAttributePath(List<? extends MetaAttribute> pathElements); MetaAttributePath(MetaAttribute... pathElements); ...
@Test public void getLast() { Assert.assertEquals(attr2, path.getLast()); } @Test public void getLastForEmptyPath() { Assert.assertNull(MetaAttributePath.EMPTY_PATH.getLast()); }
MetaAttributePath implements Iterable<MetaAttribute> { @Override public Iterator<MetaAttribute> iterator() { return Collections.unmodifiableList(Arrays.asList(pathElements)).iterator(); } MetaAttributePath(List<? extends MetaAttribute> pathElements); MetaAttributePath(MetaAttribute... pathElements); MetaAttributePath ...
@Test public void iterator() { Iterator<MetaAttribute> iterator = path.iterator(); Assert.assertTrue(iterator.hasNext()); Assert.assertEquals("a", iterator.next().getName()); Assert.assertEquals("b", iterator.next().getName()); Assert.assertFalse(iterator.hasNext()); }
MetaAttributePath implements Iterable<MetaAttribute> { public MetaAttribute getElement(int index) { return pathElements[index]; } MetaAttributePath(List<? extends MetaAttribute> pathElements); MetaAttributePath(MetaAttribute... pathElements); MetaAttributePath subPath(int startIndex); MetaAttributePath subPath(int sta...
@Test public void getElement() { Assert.assertEquals(attr1, path.getElement(0)); Assert.assertEquals(attr2, path.getElement(1)); }
MetaAttributePath implements Iterable<MetaAttribute> { public MetaAttributePath subPath(int startIndex) { MetaAttribute[] range = Arrays.copyOfRange(pathElements, startIndex, pathElements.length); return new MetaAttributePath(range); } MetaAttributePath(List<? extends MetaAttribute> pathElements); MetaAttributePath(Me...
@Test public void subPath() { MetaAttributePath subPath = path.subPath(1); Assert.assertEquals(1, subPath.length()); Assert.assertEquals(attr2, subPath.getElement(0)); }
ResourcePermission { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + (deleteAllowed ? 1231 : 1237); result = prime * result + (getAllowed ? 1231 : 1237); result = prime * result + (patchAllowed ? 1231 : 1237); result = prime * result + (postAllowed ? 1231 : 1237); retur...
@Test public void testHashCode() { Assert.assertEquals(ResourcePermission.ALL.hashCode(), ResourcePermission.ALL.hashCode()); Assert.assertNotEquals(ResourcePermission.DELETE.hashCode(), ResourcePermission.ALL.hashCode()); Assert.assertNotEquals(ResourcePermission.GET.hashCode(), ResourcePermission.ALL.hashCode()); Ass...
MetaAttributePath implements Iterable<MetaAttribute> { public String render(String delimiter) { if (pathElements.length == 0) { return ""; } else if (pathElements.length == 1) { return pathElements[0].getName(); } else { StringBuilder builder = new StringBuilder(pathElements[0].getName()); for (int i = 1; i < pathEleme...
@Test public void render() { Assert.assertEquals("a.b", path.toString()); }
MetaAttributePath implements Iterable<MetaAttribute> { @Override public boolean equals(Object obj) { if (obj instanceof MetaAttributePath) { MetaAttributePath other = (MetaAttributePath) obj; return Arrays.equals(pathElements, other.pathElements); } return false; } MetaAttributePath(List<? extends MetaAttribute> pathEl...
@Test public void equals() { Assert.assertTrue(path.equals(path)); Assert.assertFalse(path.equals(new Object())); }
MetaDataObject extends MetaType { public MetaAttributePath resolvePath(List<String> attrPath, boolean includeSubTypes) { MetaAttributeFinder finder = includeSubTypes ? SUBTYPE_ATTRIBUTE_FINDER : DEFAULT_ATTRIBUTE_FINDER; return resolvePath(attrPath, finder); } @JsonIgnore // TODO MetaAttribute getVersionAttribute(); L...
@Test(expected = IllegalArgumentException.class) public void checkResolvePathWithNullNotAllowed() { MetaResource meta = resourceProvider.getMeta(Task.class); meta.resolvePath(null); } @Test public void checkResolveEmptyPath() { MetaResource meta = resourceProvider.getMeta(Task.class); Assert.assertEquals(MetaAttributeP...
MetaDataObject extends MetaType { public MetaAttribute findAttribute(String name, boolean includeSubTypes) { if (hasAttribute(name)) { return getAttribute(name); } if (includeSubTypes) { List<? extends MetaDataObject> transitiveSubTypes = getSubTypes(true, true); for (MetaDataObject subType : transitiveSubTypes) { if (...
@Test public void checkResolveSubtypeAttribute() { MetaResource meta = resourceProvider.getMeta(Task.class); Assert.assertNotNull(meta.findAttribute("subTypeValue", true)); } @Test(expected = IllegalStateException.class) public void checkCannotResolveSubtypeAttributeWithoutIncludingSubtypes() { MetaResource meta = reso...
MetaDataObject extends MetaType { public MetaAttribute getAttribute(String name) { setupCache(); MetaAttribute attr = attrMap.get(name); PreconditionUtil.assertNotNull(getName() + "." + name, attr); return attr; } @JsonIgnore // TODO MetaAttribute getVersionAttribute(); List<? extends MetaAttribute> getAttributes(); v...
@Test public void checkNestedObject() { MetaJsonObject meta = resourceProvider.getMeta(ProjectData.class); Assert.assertEquals("ProjectData", meta.getName()); Assert.assertEquals("resources.types.projectdata", meta.getId()); Assert.assertNotNull(meta.getAttribute("data").getType()); }
ResourcePermission { public ResourcePermission xor(ResourcePermission other) { boolean mergePush = postAllowed ^ other.postAllowed; boolean mergeGet = getAllowed ^ other.getAllowed; boolean mergePatch = patchAllowed ^ other.patchAllowed; boolean mergeDelete = deleteAllowed ^ other.deleteAllowed; return new ResourcePerm...
@Test public void xor() { Assert.assertTrue(ResourcePermission.DELETE.xor(ResourcePermission.DELETE).isEmpty()); Assert.assertTrue(ResourcePermission.GET.xor(ResourcePermission.GET).isEmpty()); Assert.assertEquals(ResourcePermission.create(false, true, false, true), ResourcePermission.GET.xor(ResourcePermission.DELETE)...
MetaMapAttribute extends MetaAttribute { public Object getKey() { MetaType keyType = mapType.getKeyType(); TypeParser typeParser = new TypeParser(); return typeParser.parse(keyString, (Class) keyType.getImplementationClass()); } MetaMapAttribute(MetaMapType mapType, MetaAttribute mapAttr, String keyString); @Override M...
@Test public void getKey() { MetaType keyType = Mockito.mock(MetaType.class); Mockito.when(keyType.getImplementationClass()).thenReturn((Class) Integer.class); Mockito.when(mapType.getKeyType()).thenReturn(keyType); Assert.assertEquals(Integer.valueOf(13), impl.getKey()); }
MetaMapAttribute extends MetaAttribute { @Override public boolean isLazy() { return mapAttr.isLazy(); } MetaMapAttribute(MetaMapType mapType, MetaAttribute mapAttr, String keyString); @Override MetaType getType(); @Override Object getValue(Object dataObject); @Override void setValue(Object dataObject, Object value); Ob...
@Test public void checkForwardIsLazy() { impl.isLazy(); Mockito.verify(mapAttr, Mockito.times(1)).isLazy(); }
MetaMapAttribute extends MetaAttribute { @Override public boolean isDerived() { return mapAttr.isDerived(); } MetaMapAttribute(MetaMapType mapType, MetaAttribute mapAttr, String keyString); @Override MetaType getType(); @Override Object getValue(Object dataObject); @Override void setValue(Object dataObject, Object valu...
@Test public void checkForwardIsDerived() { impl.isDerived(); Mockito.verify(mapAttr, Mockito.times(1)).isDerived(); }
MetaMapAttribute extends MetaAttribute { @Override public Collection<Annotation> getAnnotations() { throw new UnsupportedOperationException(); } MetaMapAttribute(MetaMapType mapType, MetaAttribute mapAttr, String keyString); @Override MetaType getType(); @Override Object getValue(Object dataObject); @Override void setV...
@Test(expected = UnsupportedOperationException.class) public void checkGetAnnotationsNotSupported() { impl.getAnnotations(); }
MetaMapAttribute extends MetaAttribute { @Override public <T extends Annotation> T getAnnotation(Class<T> clazz) { throw new UnsupportedOperationException(); } MetaMapAttribute(MetaMapType mapType, MetaAttribute mapAttr, String keyString); @Override MetaType getType(); @Override Object getValue(Object dataObject); @Ove...
@Test(expected = UnsupportedOperationException.class) public void checkGetAnnotationNotSupported() { impl.getAnnotation(null); }
MetaMapAttribute extends MetaAttribute { public void setOppositeAttribute(MetaAttribute oppositeAttr) { throw new UnsupportedOperationException(); } MetaMapAttribute(MetaMapType mapType, MetaAttribute mapAttr, String keyString); @Override MetaType getType(); @Override Object getValue(Object dataObject); @Override void ...
@Test(expected = UnsupportedOperationException.class) public void checkSetOppositeAttributeNotSupported() { impl.setOppositeAttribute(null); }
MetaMapAttribute extends MetaAttribute { @Override public boolean isAssociation() { return mapAttr.isAssociation(); } MetaMapAttribute(MetaMapType mapType, MetaAttribute mapAttr, String keyString); @Override MetaType getType(); @Override Object getValue(Object dataObject); @Override void setValue(Object dataObject, Obj...
@Test public void checkForwardIsAssociation() { impl.isAssociation(); Mockito.verify(mapAttr, Mockito.times(1)).isAssociation(); }
MetaMapAttribute extends MetaAttribute { @Override public boolean isVersion() { throw new UnsupportedOperationException(); } MetaMapAttribute(MetaMapType mapType, MetaAttribute mapAttr, String keyString); @Override MetaType getType(); @Override Object getValue(Object dataObject); @Override void setValue(Object dataObje...
@Test(expected = UnsupportedOperationException.class) public void getVersionNotSupported() { impl.isVersion(); }
MetaMapAttribute extends MetaAttribute { public boolean isId() { throw new UnsupportedOperationException(); } MetaMapAttribute(MetaMapType mapType, MetaAttribute mapAttr, String keyString); @Override MetaType getType(); @Override Object getValue(Object dataObject); @Override void setValue(Object dataObject, Object valu...
@Test(expected = UnsupportedOperationException.class) public void isIdNotSupported() { impl.isId(); }
MetaMapAttribute extends MetaAttribute { @Override public MetaAttribute getOppositeAttribute() { throw new UnsupportedOperationException(); } MetaMapAttribute(MetaMapType mapType, MetaAttribute mapAttr, String keyString); @Override MetaType getType(); @Override Object getValue(Object dataObject); @Override void setValu...
@Test(expected = UnsupportedOperationException.class) public void getOppositeAttributeNotSupported() { impl.getOppositeAttribute(); }
ResourcePermission { public ResourcePermission and(ResourcePermission other) { boolean mergePush = postAllowed && other.postAllowed; boolean mergeGet = getAllowed && other.getAllowed; boolean mergePatch = patchAllowed && other.patchAllowed; boolean mergeDelete = deleteAllowed && other.deleteAllowed; return new Resource...
@Test public void and() { Assert.assertEquals(ResourcePermission.DELETE, ResourcePermission.DELETE.or(ResourcePermission.DELETE)); Assert.assertEquals(ResourcePermission.GET, ResourcePermission.GET.or(ResourcePermission.GET)); Assert.assertTrue(ResourcePermission.GET.and(ResourcePermission.DELETE).isEmpty()); }
MetaMapAttribute extends MetaAttribute { @Override public Object getValue(Object dataObject) { throw new UnsupportedOperationException(); } MetaMapAttribute(MetaMapType mapType, MetaAttribute mapAttr, String keyString); @Override MetaType getType(); @Override Object getValue(Object dataObject); @Override void setValue(...
@Test(expected = UnsupportedOperationException.class) public void getValueNotSupported() { impl.getValue(null); }
MetaMapAttribute extends MetaAttribute { @Override public void addValue(Object dataObject, Object value) { throw new UnsupportedOperationException(); } MetaMapAttribute(MetaMapType mapType, MetaAttribute mapAttr, String keyString); @Override MetaType getType(); @Override Object getValue(Object dataObject); @Override vo...
@Test(expected = UnsupportedOperationException.class) public void addValueNotSupported() { impl.addValue(null, null); }
MetaMapAttribute extends MetaAttribute { @Override public void removeValue(Object dataObject, Object value) { throw new UnsupportedOperationException(); } MetaMapAttribute(MetaMapType mapType, MetaAttribute mapAttr, String keyString); @Override MetaType getType(); @Override Object getValue(Object dataObject); @Override...
@Test(expected = UnsupportedOperationException.class) public void removeValueNotSupported() { impl.removeValue(null, null); }
MetaMapAttribute extends MetaAttribute { @Override public void setValue(Object dataObject, Object value) { throw new UnsupportedOperationException(); } MetaMapAttribute(MetaMapType mapType, MetaAttribute mapAttr, String keyString); @Override MetaType getType(); @Override Object getValue(Object dataObject); @Override vo...
@Test(expected = UnsupportedOperationException.class) public void setValueNotSupported() { impl.setValue(null, null); }
MetaKey extends MetaElement { public String toKeyString(Object id) { if (id == null) { return null; } PreconditionUtil.assertEquals("compound primary key not supported", 1, elements.size()); MetaAttribute keyAttr = elements.get(0); MetaType keyType = keyAttr.getType(); if (keyType instanceof MetaDataObject) { MetaDataO...
@Test public void testToKeyStringWithNull() { MetaKey key = new MetaKey(); Assert.assertNull(key.toKeyString(null)); }
MetaElement implements Cloneable { public MetaDataObject asDataObject() { if (!(this instanceof MetaDataObject)) { throw new IllegalStateException(getName() + " not a MetaDataObject"); } return (MetaDataObject) this; } MetaElement getParent(); void setParent(MetaElement parent); List<MetaElement> getChildren(); void s...
@Test(expected = IllegalStateException.class) public void checkDataObjectCast() { new MetaKey().asDataObject(); }
MetaElement implements Cloneable { public MetaType asType() { if (!(this instanceof MetaType)) { throw new IllegalStateException(getName() + " not a MetaEntity"); } return (MetaType) this; } MetaElement getParent(); void setParent(MetaElement parent); List<MetaElement> getChildren(); void setChildren(List<MetaElement>...
@Test(expected = IllegalStateException.class) public void checkTypeCast() { new MetaKey().asType(); }
JpaEntityRepositoryBase extends JpaRepositoryBase<T> implements ResourceRepository<T, I>, ResourceRegistryAware { @Override public Class<T> getResourceClass() { return repositoryConfig.getResourceClass(); } JpaEntityRepositoryBase(Class<T> entityClass); JpaEntityRepositoryBase(JpaRepositoryConfig<T> config); JpaQuer...
@Test public void testGetResourceType() { Assert.assertEquals(TestEntity.class, repo.getResourceClass()); }
JpaEntityRepositoryBase extends JpaRepositoryBase<T> implements ResourceRepository<T, I>, ResourceRegistryAware { public Class<?> getEntityClass() { return repositoryConfig.getEntityClass(); } JpaEntityRepositoryBase(Class<T> entityClass); JpaEntityRepositoryBase(JpaRepositoryConfig<T> config); JpaQueryFactory getQu...
@Test public void testGetEntityType() { Assert.assertEquals(TestEntity.class, repo.getEntityClass()); }
ResourcePermission { public ResourcePermission or(ResourcePermission other) { boolean mergePush = postAllowed || other.postAllowed; boolean mergeGet = getAllowed || other.getAllowed; boolean mergePatch = patchAllowed || other.patchAllowed; boolean mergeDelete = deleteAllowed || other.deleteAllowed; return new ResourceP...
@Test public void or() { Assert.assertEquals(ResourcePermission.DELETE, ResourcePermission.DELETE.or(ResourcePermission.DELETE)); Assert.assertEquals(ResourcePermission.GET, ResourcePermission.GET.or(ResourcePermission.GET)); Assert.assertEquals(ResourcePermission.create(false, true, false, true), ResourcePermission.GE...
MyService { public int calculateUserAge(User user) { return Period.between(user.getDateOfBirth(), LocalDate.now()).getYears(); } int calculateUserAge(User user); }
@Test public void testService() { MyService myService = new MyService(); User user = new User("John", "john@yahoo.com"); user.setDateOfBirth(LocalDate.of(1980, Month.APRIL, 20)); logger.info("Age of user {} is {}", () -> user.getName(), () -> myService.calculateUserAge(user)); }
EmployeeService { public double calculateBonus(Employee user) { return 0.1 * user.getSalary(); } double calculateBonus(Employee user); }
@Test public void testParameter() { Employee employee = new Employee("john@gmail.com", "John", 2000); if (logger.isDebugEnabled()) { logger.debug("The bonus for employee: " + employee.getName() + " is " + employeeService.calculateBonus(employee)); } logger.debug("The bonus for employee {} is {}", employee.getName(), em...
Castle { public static String clientId() { return instance.identifier; } private Castle(Application application, CastleConfiguration castleConfiguration); static void configure(Application application, CastleConfiguration configuration); static void configure(Application application, String publishableKey); static voi...
@Test public void testDeviceIdentifier() { Assert.assertNotNull(Castle.clientId()); } @Test public void testRequestInterceptor() throws IOException { Request request = new Request.Builder() .url("https: .build(); Response response = client.newCall(request).execute(); Assert.assertEquals(Castle.clientId(), response.requ...
Castle { public static boolean flushIfNeeded(String url) { if (isUrlWhiteListed(url)) { flush(); return true; } return false; } private Castle(Application application, CastleConfiguration castleConfiguration); static void configure(Application application, CastleConfiguration configuration); static void configure(Appl...
@Test public void testflushIfNeeded() { boolean flushed = Castle.flushIfNeeded("https: Assert.assertTrue(flushed); flushed = Castle.flushIfNeeded("https: Assert.assertFalse(flushed); }
Castle { public static void reset() { Castle.flush(); Castle.userId(null); Castle.userSignature(null); } private Castle(Application application, CastleConfiguration castleConfiguration); static void configure(Application application, CastleConfiguration configuration); static void configure(Application application, St...
@Test public void testReset() { Castle.reset(); Assert.assertNull(Castle.userId()); }
Castle { static boolean isUrlWhiteListed(String urlString) { try { URL url = new URL(urlString); String baseUrl = url.getProtocol() + ": if (Castle.configuration().baseURLWhiteList() != null && !Castle.configuration().baseURLWhiteList().isEmpty()) { if (Castle.configuration().baseURLWhiteList().contains(baseUrl)) { ret...
@Test public void testWhiteList() { Assert.assertFalse(Castle.isUrlWhiteListed("invalid url")); }
Castle { public static String userAgent() { return Utils.sanitizeHeader(String.format(Locale.US, "%s/%s (%d) (%s %s; Android %s; Castle %s)", instance.appName, instance.appVersion, instance.appBuild, Build.MANUFACTURER, Build.MODEL, Build.VERSION.RELEASE, BuildConfig.VERSION_NAME)); } private Castle(Application applic...
@Test @Config(manifest = "AndroidManifest.xml") public void testUserAgent() { String regex = "[a-zA-Z0-9\\s._-]+/[0-9]+\\.[0-9]+\\.?[0-9]*(-[a-zA-Z0-9]*)? \\([a-zA-Z0-9-_.]+\\) \\([a-zA-Z0-9\\s]+; Android [0-9]+\\.?[0-9]*; Castle [0-9]+\\.[0-9]+\\.?[0-9]*(-[a-zA-Z0-9]*)?\\)"; Pattern pattern = Pattern.compile(regex); M...
Solve { Solve() { } Solve(); int solve(int dimension, int[][] gridCopy); static int[] rc2box(int i, int j); }
@Test public void testInvalidGrid() { Solve grid1 = new Solve(); int[][] grid = { { 4, 8, 3, 7, 6, 9, 2, 1, 5 }, { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, { 1, 2, 3, 4, 5, 6, 7...