ParameterValueFactory { public ParameterValue create(String value, String language) { return new StringParameterValue(value, language); } ParameterValueFactory(MetamodelProvider metamodelProvider); ParameterValue createVariableValue(String name); ParameterValue createVariableValue(Integer position); ParameterValue create(String value, String language); ParameterValue create(Object value); ParameterValue createUntyped(Object value);  }
@Test void createStringValueWithoutLanguageTag() { final ParameterValue value = sut.create("test"); assertEquals("test", value.getValue()); assertEquals("\"test\"", value.getQueryString()); }
@Test void createStringValueWithLanguageTag() { final ParameterValue value = sut.create("test", "en"); assertEquals("test", value.getValue()); assertEquals("\"test\"@en", value.getQueryString()); }
@Test void createBooleanValue() { final ParameterValue value = sut.create(true); assertEquals(Boolean.TRUE, value.getValue()); assertEquals("\"true\"^^<" + XSD.BOOLEAN + ">", value.getQueryString()); }
@Test void createShortValue() { final ParameterValue value = sut.create((short) 117); assertEquals((short) 117, value.getValue()); assertEquals("\"117\"^^<" + XSD.SHORT + ">", value.getQueryString()); }
@Test void createIntegerValue() { final ParameterValue value = sut.create(117); assertEquals(117, value.getValue()); assertEquals("\"117\"^^<" + XSD.INT + ">", value.getQueryString()); }
@Test void createLongValue() { final long v = System.currentTimeMillis(); final ParameterValue value = sut.create(v); assertEquals(v, value.getValue()); assertEquals("\"" + v + "\"^^<" + XSD.LONG + ">", value.getQueryString()); }
@Test void createFloatValue() { final ParameterValue value = sut.create(3.14f); assertEquals(3.14f, value.getValue()); assertEquals("\"3.14\"^^<" + XSD.FLOAT + ">", value.getQueryString()); }
@Test void createDoubleValue() { final ParameterValue value = sut.create(3.14); assertEquals(3.14, value.getValue()); assertEquals("\"3.14\"^^<" + XSD.DOUBLE + ">", value.getQueryString()); }
@Test void createDateValue() { final Date date = new Date(); final ParameterValue value = sut.create(date); assertEquals(date, value.getValue()); assertEquals("\"" + date.toInstant().toString() + "\"^^<" + XSD.DATETIME + ">", value.getQueryString()); }
@Test void createUriValue() { final URI uri = URI.create("http: final ParameterValue value = sut.create(uri); assertEquals(uri, value.getValue()); assertEquals("<" + uri.toString() + ">", value.getQueryString()); }
@Test void createUrlValue() throws Exception { final URL url = new URL("http: final ParameterValue value = sut.create(url); assertEquals(url.toURI(), value.getValue()); assertEquals("<" + url.toString() + ">", value.getQueryString()); }
@Test void createValueSupportsCreatingParameterValueFromEntityInstance() { final OWLClassA value = Generators.generateOwlClassAInstance(); when(metamodelProvider.isEntityType(value.getClass())).thenReturn(true); final ParameterValue result = sut.create(value); assertThat(result, instanceOf(EntityParameterValue.class)); assertEquals(value, result.getValue()); }
@Test void createLocalDateTimeValueCreatesDateTimeParameter() { final LocalDateTime localDateTime = LocalDateTime.now(); final ParameterValue value = sut.create(localDateTime); assertEquals("\"" + localDateTime.toString() + "\"^^<" + XSD.DATETIME + ">", value.getQueryString()); }
@Test void createInstantValueCreatesDateTimeParameter() { final Instant instant = Instant.now(); final ParameterValue value = sut.create(instant); assertEquals("\"" + instant.toString() + "\"^^<" + XSD.DATETIME + ">", value.getQueryString()); }
@Test void createZonedDateTimeValueCreatesDateTimeParameter() { final ZonedDateTime zonedDateTime = ZonedDateTime.now(); final ParameterValue value = sut.create(zonedDateTime); assertEquals( "\"" + zonedDateTime.toOffsetDateTime().toString() + "\"^^<" + XSD.DATETIME + ">", value.getQueryString()); }
@Test void createOffsetDateTimeValueCreatesDateTimeParameter() { final OffsetDateTime offsetDateTime = OffsetDateTime.now(); final ParameterValue value = sut.create(offsetDateTime); assertEquals( "\"" + offsetDateTime.toString() + "\"^^<" + XSD.DATETIME + ">", value.getQueryString()); }
@Test void createLocalDateValueCreatesDateParameter() { final LocalDate localDate = LocalDate.now(); final ParameterValue value = sut.create(localDate); assertEquals("\"" + localDate.toString() + "\"^^<" + XSD.DATE + ">", value.getQueryString()); }
@Test void createLocalTimeValueCreatesTimeParameter() { final LocalTime localTime = LocalTime.now(); final ParameterValue value = sut.create(localTime); assertEquals("\"" + localTime.toString() + "\"^^<" + XSD.TIME + ">", value.getQueryString()); }
@Test void createOffsetTimeValueCreatesTimeParameter() { final OffsetTime offsetTime = OffsetTime.now(); final ParameterValue value = sut.create(offsetTime); assertEquals("\"" + offsetTime.toString() + "\"^^<" + XSD.TIME + ">", value.getQueryString()); }
@Test void createCollectionValueCreatesCollectionOfUriParametersValuesForUriElements() { final Collection<URI> uris = Arrays .asList(Generators.createIndividualIdentifier(), Generators.createIndividualIdentifier()); final ParameterValue result = sut.create(uris); assertEquals(uris.stream().map(u -> "<" + u + ">").collect(Collectors.joining(",")), result.getQueryString()); }
@Test void createCollectionValueCreatesCollectionOfLiteralsForLiteralElements() { final Collection<Object> values = Arrays.asList(117, false); final ParameterValue result = sut.create(values); assertEquals("\"" + 117 + "\"^^<" + XSD.INT + ">,\"" + false + "\"^^<" + XSD.BOOLEAN + ">", result.getQueryString()); }
@Test void createCollectionValueCreatesCollectionOfUrisForEntityElements() throws Exception { final Collection<OWLClassA> values = Arrays .asList(Generators.generateOwlClassAInstance(), Generators.generateOwlClassAInstance()); when(metamodelProvider.isEntityType(OWLClassA.class)).thenReturn(true); final MetamodelMocks mocks = new MetamodelMocks(); final Metamodel metamodel = mock(Metamodel.class); mocks.setMocks(metamodel); when(metamodelProvider.getMetamodel()).thenReturn(metamodel); final ParameterValue result = sut.create(values); assertEquals(values.stream().map(a -> "<" + a.getUri() + ">").collect(Collectors.joining(",")), result.getQueryString()); }