XSDValueSpaceValidator implements Validator { @Override public void addValueSpaceCheck(MethodSpec.Builder methodBuilder, ParameterSpec symbol, RDFSClazz range) { if (range.getResourceAsString().startsWith(XSD.NS)) { switch (range.getResourceAsString()) { case XSD.NORMALIZED_STRING: addNormalizedStringValidation(methodBuilder, symbol); break; case XSD.TOKEN: addTokenValidation(methodBuilder, symbol); break; case XSD.LANGUAGE: addLanguageValidation(methodBuilder, symbol); break; case XSD.NON_POSITIVE_INTEGER: addNonPositiveValidation(methodBuilder, symbol); break; case XSD.NEGATIVE_INTEGER: addNegativeValidation(methodBuilder, symbol); break; case XSD.NON_NEGATIVE_INTEGER: addNonNegativeValidation(methodBuilder, symbol); break; case XSD.UNSIGNED_LONG: addUnsignedValidation(methodBuilder, symbol); break; case XSD.UNSIGNED_INT: addUnsignedIntegerValidation(methodBuilder, symbol); break; case XSD.UNSIGNED_SHORT: addUnsignedShortValidation(methodBuilder, symbol); break; case XSD.UNSIGNED_BYTE: addUnsignedByteValidation(methodBuilder, symbol); break; case XSD.POSITIVE_INTEGER: addPositiveValidation(methodBuilder, symbol); break; } } }  @Override void addValueSpaceCheck(MethodSpec.Builder methodBuilder, ParameterSpec symbol, RDFSClazz range); @Override String getValueSpaceDefinition(RDFSClazz clazz); @Override boolean isValueSpaceConstrained(RDFSClazz clazz);  }
@Test public void testNonPositive() throws Exception { BuildableRDFSClazz xsdNonPositiveInt = anno4j.createObject(BuildableRDFSClazz.class, (Resource) new URIImpl(XSD.NON_POSITIVE_INTEGER)); MethodSpec.Builder methodBuilder = method.toBuilder(); validator.addValueSpaceCheck(methodBuilder, param, xsdNonPositiveInt); String code = methodBuilder.build().code.toString(); Matcher matcher = Pattern.compile("if\\s*\\((x\\s*>\\s*0|0\\s*<\\s*x)\\)").matcher(code); assertTrue(matcher.find()); }
@Test public void testNegative() throws Exception { BuildableRDFSClazz xsdNegativeInt = anno4j.createObject(BuildableRDFSClazz.class, (Resource) new URIImpl(XSD.NEGATIVE_INTEGER)); MethodSpec.Builder methodBuilder = method.toBuilder(); validator.addValueSpaceCheck(methodBuilder, param, xsdNegativeInt); String code = methodBuilder.build().code.toString(); Matcher matcher = Pattern.compile("if\\s*\\((x\\s*>=\\s*0|0\\s*<=\\s*x)\\)").matcher(code); assertTrue(matcher.find()); }
@Test public void testNonNegative() throws Exception { BuildableRDFSClazz xsdNonNegativeInt = anno4j.createObject(BuildableRDFSClazz.class, (Resource) new URIImpl(XSD.NON_NEGATIVE_INTEGER)); MethodSpec.Builder methodBuilder = method.toBuilder(); validator.addValueSpaceCheck(methodBuilder, param, xsdNonNegativeInt); String code = methodBuilder.build().code.toString(); Matcher matcher = Pattern.compile("if\\s*\\((x\\s*<\\s*0|0\\s*>\\s*x)\\)").matcher(code); assertTrue(matcher.find()); }
@Test public void testUnsigned() throws Exception { BuildableRDFSClazz xsdUnsignedInt = anno4j.createObject(BuildableRDFSClazz.class, (Resource) new URIImpl(XSD.UNSIGNED_INT)); MethodSpec.Builder methodBuilder = method.toBuilder(); validator.addValueSpaceCheck(methodBuilder, param, xsdUnsignedInt); String code = methodBuilder.build().code.toString(); Matcher matcher = Pattern.compile("if\\s*\\((x\\s*<\\s*0|0\\s*>\\s*x)\\)").matcher(code); assertTrue(matcher.find()); }
@Test public void testPositive() throws Exception { BuildableRDFSClazz xsdPositiveInt = anno4j.createObject(BuildableRDFSClazz.class, (Resource) new URIImpl(XSD.POSITIVE_INTEGER)); MethodSpec.Builder methodBuilder = method.toBuilder(); validator.addValueSpaceCheck(methodBuilder, param, xsdPositiveInt); String code = methodBuilder.build().code.toString(); Matcher matcher = Pattern.compile("if\\s*\\((x\\s*<=\\s*0|0\\s*>=\\s*x)\\)").matcher(code); assertTrue(matcher.find()); }