public static Micronode mockMicronode(String microschemaName, User user) { Micronode micronode = mock(Micronode.class); when(micronode.getUuid()).thenReturn(UUID_1); MicroschemaContainer microschemaContainer = mockMicroschemaContainer(microschemaName, user); MicroschemaContainerVersion latestVersion = microschemaContainer.getLatestVersion(); when(micronode.getSchemaContainerVersion()).thenReturn(latestVersion); MicroschemaModel microschema = microschemaContainer.getLatestVersion().getSchema(); when(micronode.getSchemaContainerVersion().getSchema()).thenReturn(microschema); // longitude field NumberGraphField longitudeField = mock(NumberGraphField.class); when(longitudeField.getNumber()).thenReturn(16.373063840833); when(micronode.getNumber("longitude")).thenReturn(longitudeField); // latitude field NumberGraphField latitudeField = mock(NumberGraphField.class); when(latitudeField.getNumber()).thenReturn(16.373063840833); when(micronode.getNumber("latitude")).thenReturn(latitudeField); when(micronode.getElementVersion()).thenReturn(UUID_3); return micronode; }
/** * Assert that the micronode uses the given microschema. * * @param microschemaContainerVersion * microschema container * @return Fluent API */ public MicronodeAssert isOf(MicroschemaContainerVersion microschemaContainerVersion) { assertTrue(actual.getSchemaContainerVersion().getUuid().equals(microschemaContainerVersion.getUuid())); return this; }
/** * Assert that the micronode contains the string field with the given value. * * @param name * Name of the string field * @param value * Value of the string * @return Fluent API */ public MicronodeAssert containsStringField(String name, String value) { assertThat(actual).as(descriptionText()).isNotNull(); assertThat(actual.getString(name)).as(descriptionText() + " string field '" + name + "'").isNotNull(); assertThat(actual.getString(name).getString()).as(descriptionText() + " string field '" + name + "' value").isEqualTo(value); return this; }
public GraphQLType createType(GraphQLContext context) { Map<String, GraphQLObjectType> types = generateMicroschemaFieldType(context); // No microschemas have been found - We need to add a dummy type in order to keep the type system working if (types.isEmpty()) { types.put("dummy", newObject().name("dummy").field(newFieldDefinition().name("dummy").type(GraphQLString).staticValue(null).build()).description("Placeholder dummy microschema type").build()); } GraphQLObjectType[] typeArray = types.values().toArray(new GraphQLObjectType[types.values().size()]); GraphQLUnionType fieldType = newUnionType().name(MICRONODE_TYPE_NAME).possibleTypes(typeArray).description("Fields of the micronode.") .typeResolver(env -> { Object object = env.getObject(); if (object instanceof Micronode) { Micronode fieldContainer = (Micronode) object; MicroschemaContainerVersion micronodeFieldSchema = fieldContainer.getSchemaContainerVersion(); String schemaName = micronodeFieldSchema.getName(); GraphQLObjectType foundType = types.get(schemaName); return foundType; } return null; }).build(); return fieldType; }
JsonObject itemMap = new JsonObject(); Micronode micronode = item.getMicronode(); MicroschemaContainerVersion microschameContainerVersion = micronode.getSchemaContainerVersion(); addMicroschema(itemMap, microschameContainerVersion); addFields(itemMap, "fields-" + microschameContainerVersion.getName(), micronode, if (micronode != null) { JsonObject micronodeMap = new JsonObject(); addMicroschema(micronodeMap, micronode.getSchemaContainerVersion()); addFields(micronodeMap, "fields-" + micronode.getSchemaContainerVersion().getName(), micronode, micronode.getSchemaContainerVersion().getSchema().getFields()); fieldsMap.put(fieldSchema.getName(), micronodeMap);