src_fm_fc_ms_ff
stringlengths
43
86.8k
target
stringlengths
20
276k
SignedBatchScanner implements BatchScanner { @Override public void clearScanIterators() { valueScanner.clearScanIterators(); if (signatureScanner != null) { signatureScanner.clearScanIterators(); } } SignedBatchScanner(Connector connector, String tableName, Authorizations authorizations, int numQueryThreads, SignatureC...
@Test public void clearScanIteratorsTest() throws Exception { when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner); new SignedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("config1.ini"), aliceKeyContainers.get(ValueSigner.RSA_PSS)) .clearScanIterators(); ...
SignedBatchScanner implements BatchScanner { @Override public void setRanges(Collection<Range> collection) { valueScanner.setRanges(collection); if (signatureScanner != null) { signatureScanner.setRanges(collection); } } SignedBatchScanner(Connector connector, String tableName, Authorizations authorizations, int numQue...
@Test public void setRangesTest() throws Exception { Collection<Range> ranges = Collections.singletonList(new Range("test")); when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner); new SignedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("config1.ini"), alic...
SignedBatchScanner implements BatchScanner { @Override public void close() { valueScanner.close(); if (signatureScanner != null) { signatureScanner.close(); } } SignedBatchScanner(Connector connector, String tableName, Authorizations authorizations, int numQueryThreads, SignatureConfig signatureConfig, SignatureK...
@Test public void closeTest() throws Exception { when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner); new SignedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("config1.ini"), aliceKeyContainers.get(ValueSigner.RSA_PSS)).close(); verify(mockScanner).close()...
SignedBatchScanner implements BatchScanner { @Override public void fetchColumn(Column column) { valueScanner.fetchColumn(column); if (signatureScanner != null) { signatureScanner.fetchColumn(column); } } SignedBatchScanner(Connector connector, String tableName, Authorizations authorizations, int numQueryThreads, Signat...
@Test public void fetchColumnTest() throws Exception { Column column = new Column(new Text(new byte[] {1}), new Text(new byte[] {2})); when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner); new SignedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("config1.in...
SignedBatchScanner implements BatchScanner { @Override public void fetchColumnFamily(Text col) { valueScanner.fetchColumnFamily(col); if (signatureScanner != null) { signatureScanner.fetchColumnFamily(col); } } SignedBatchScanner(Connector connector, String tableName, Authorizations authorizations, int numQueryThreads,...
@Test public void fetchColumnFamilyTest() throws Exception { Text colF = new Text(new byte[] {1}); when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner); new SignedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("config1.ini"), aliceKeyContainers.get(ValueSig...
SignedBatchScanner implements BatchScanner { @Override public Authorizations getAuthorizations() { return valueScanner.getAuthorizations(); } SignedBatchScanner(Connector connector, String tableName, Authorizations authorizations, int numQueryThreads, SignatureConfig signatureConfig, SignatureKeyContainer keys); ...
@Test public void getAuthorizationsTest() throws Exception { when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner); when(mockScanner.getAuthorizations()).thenReturn(authorizations); Authorizations auths = new SignedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getCon...
SignedBatchScanner implements BatchScanner { @Override public SamplerConfiguration getSamplerConfiguration() { return valueScanner.getSamplerConfiguration(); } SignedBatchScanner(Connector connector, String tableName, Authorizations authorizations, int numQueryThreads, SignatureConfig signatureConfig, SignatureKe...
@Test public void getSamplerConfigurationTest() throws Exception { when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner); SamplerConfiguration config = new SamplerConfiguration("test"); when(mockScanner.getSamplerConfiguration()).thenReturn(config); SamplerConfiguration value = n...
SignedBatchScanner implements BatchScanner { @Override public void setSamplerConfiguration(SamplerConfiguration samplerConfiguration) { valueScanner.setSamplerConfiguration(samplerConfiguration); if (signatureScanner != null) { signatureScanner.setSamplerConfiguration(samplerConfiguration); } } SignedBatchScanner(Conne...
@Test public void setSamplerConfigurationTest() throws Exception { when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner); SamplerConfiguration config = new SamplerConfiguration("test"); new SignedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("config1.ini"),...
SignedBatchScanner implements BatchScanner { @Override public void clearSamplerConfiguration() { valueScanner.clearSamplerConfiguration(); if (signatureScanner != null) { signatureScanner.clearSamplerConfiguration(); } } SignedBatchScanner(Connector connector, String tableName, Authorizations authorizations, int numQue...
@Test public void clearSamplerConfigurationTest() throws Exception { when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner); new SignedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("config1.ini"), aliceKeyContainers.get(ValueSigner.RSA_PSS)) .clearSamplerCon...
SignedScanner implements Scanner { @Override public void clearColumns() { valueScanner.clearColumns(); if (signatureScanner != null) { signatureScanner.clearColumns(); } } SignedScanner(Connector connector, String tableName, Authorizations authorizations, SignatureConfig signatureConfig, SignatureKeyContainer keys); @O...
@Test public void clearColumns() throws Exception { when(mockConnector.createScanner(TEST_TABLE, authorizations)).thenReturn(mockScanner); new SignedScanner(mockConnector, TEST_TABLE, authorizations, getConfig("config1.ini"), aliceKeyContainers.get(ValueSigner.RSA_PSS)).clearColumns(); verify(mockScanner).clearColumns(...
SignedBatchScanner implements BatchScanner { @Override public void setBatchTimeout(long l, TimeUnit timeUnit) { valueScanner.setBatchTimeout(l, timeUnit); if (signatureScanner != null) { signatureScanner.setBatchTimeout(l, timeUnit); } } SignedBatchScanner(Connector connector, String tableName, Authorizations authoriza...
@Test public void setBatchTimeoutTest() throws Exception { when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner); new SignedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("config1.ini"), aliceKeyContainers.get(ValueSigner.RSA_PSS)) .setBatchTimeout(5L, TimeU...
SignedBatchScanner implements BatchScanner { @Override public long getBatchTimeout(TimeUnit timeUnit) { return valueScanner.getBatchTimeout(timeUnit); } SignedBatchScanner(Connector connector, String tableName, Authorizations authorizations, int numQueryThreads, SignatureConfig signatureConfig, SignatureKeyContai...
@Test public void getBatchTimeoutTest() throws Exception { when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner); when(mockScanner.getBatchTimeout(TimeUnit.DAYS)).thenReturn(5L); long value = new SignedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("config1....
SignedBatchScanner implements BatchScanner { @Override public void setClassLoaderContext(String s) { valueScanner.setClassLoaderContext(s); if (signatureScanner != null) { signatureScanner.setClassLoaderContext(s); } } SignedBatchScanner(Connector connector, String tableName, Authorizations authorizations, int numQuery...
@Test public void setClassLoaderContextTest() throws Exception { when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner); new SignedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("config1.ini"), aliceKeyContainers.get(ValueSigner.RSA_PSS)) .setClassLoaderConte...
SignedBatchScanner implements BatchScanner { @Override public void clearClassLoaderContext() { valueScanner.clearClassLoaderContext(); if (signatureScanner != null) { signatureScanner.clearClassLoaderContext(); } } SignedBatchScanner(Connector connector, String tableName, Authorizations authorizations, int numQueryThre...
@Test public void clearClassLoaderContextTest() throws Exception { when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner); new SignedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("config1.ini"), aliceKeyContainers.get(ValueSigner.RSA_PSS)) .clearClassLoaderC...
SignedBatchScanner implements BatchScanner { @Override public String getClassLoaderContext() { return valueScanner.getClassLoaderContext(); } SignedBatchScanner(Connector connector, String tableName, Authorizations authorizations, int numQueryThreads, SignatureConfig signatureConfig, SignatureKeyContainer keys); ...
@Test public void getClassLoaderContextTest() throws Exception { when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner); when(mockScanner.getClassLoaderContext()).thenReturn("test"); String value = new SignedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("con...
SignedBatchScanner implements BatchScanner { @Override public long getTimeout(TimeUnit timeUnit) { return valueScanner.getTimeout(timeUnit); } SignedBatchScanner(Connector connector, String tableName, Authorizations authorizations, int numQueryThreads, SignatureConfig signatureConfig, SignatureKeyContainer keys);...
@Test public void getTimeoutTest() throws Exception { when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner); when(mockScanner.getTimeout(TimeUnit.DAYS)).thenReturn(5L); Long value = new SignedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("config1.ini"), ali...
SignedBatchScanner implements BatchScanner { @Override public void removeScanIterator(String iteratorName) { valueScanner.removeScanIterator(iteratorName); if (signatureScanner != null) { signatureScanner.removeScanIterator(iteratorName); } } SignedBatchScanner(Connector connector, String tableName, Authorizations auth...
@Test public void removeScanIteratorTest() throws Exception { when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner); new SignedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("config1.ini"), aliceKeyContainers.get(ValueSigner.RSA_PSS)) .removeScanIterator("te...
SignedBatchScanner implements BatchScanner { @Override public void updateScanIteratorOption(String iteratorName, String key, String value) { valueScanner.updateScanIteratorOption(iteratorName, key, value); if (signatureScanner != null) { signatureScanner.updateScanIteratorOption(iteratorName, key, value); } } SignedBat...
@Test public void updateScanIteratorOptionTest() throws Exception { when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner); new SignedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("config1.ini"), aliceKeyContainers.get(ValueSigner.RSA_PSS)) .updateScanIterat...
SignedBatchScanner implements BatchScanner { @Override public void setTimeout(long timeout, TimeUnit timeUnit) { valueScanner.setTimeout(timeout, timeUnit); if (signatureScanner != null) { signatureScanner.setTimeout(timeout, timeUnit); } } SignedBatchScanner(Connector connector, String tableName, Authorizations author...
@Test public void setTimeoutTest() throws Exception { when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner); new SignedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("config1.ini"), aliceKeyContainers.get(ValueSigner.RSA_PSS)).setTimeout(5L, TimeUnit.DAYS); ...
AnnotationFinder { public static <T extends Annotation> T annotationFor(Package aPkg, Class< ? extends T> whichAnnotation) { T annotation = null; if ((annotation = aPkg.getAnnotation(whichAnnotation)) == null) { annotation = find(aPkg, whichAnnotation); } return annotation; } static T annotationFor(Package aPkg, Class...
@Test public void testAnnotationForPackageShouldAcceptWildCardClass() throws Exception { Class<? extends RamlGenerators> input = RamlGenerators.class; RamlGenerators generators = annotationFor(TOP_PACKAGE, input); assertNotNull("Wildcard — null return not expected", generators); } @Test public void testAnnotationForPac...
SimpleTypeNodeHandler extends NodeHandler<SimpleTypeNode<?>> { @Override public boolean handleSafely(SimpleTypeNode<?> node, YamlEmitter emitter) throws IOException { emitter.writeValue(node); return true; } SimpleTypeNodeHandler(); @Override boolean handles(Node node); @Override boolean handleSafely(SimpleTypeNode<?> ...
@Test public void handleSafely() throws Exception { SimpleTypeNodeHandler rnh = new SimpleTypeNodeHandler(); rnh.handleSafely(goodNode, emitter); verify(emitter).writeValue(goodNode); }
DefaultNodeHandler extends NodeHandler<Node> { @Override public boolean handles(Node node) { return true; } @Override boolean handles(Node node); @Override boolean handleSafely(Node node, YamlEmitter emitter); }
@Test public void handles() throws Exception { DefaultNodeHandler handler = new DefaultNodeHandler(); assertTrue(handler.handles(node)); }
DefaultNodeHandler extends NodeHandler<Node> { @Override public boolean handleSafely(Node node, YamlEmitter emitter) { System.err.println("not handled: " + node.getClass() + ", " + Arrays.asList(node.getClass().getInterfaces())); return true; } @Override boolean handles(Node node); @Override boolean handleSafely(Node ...
@Test public void handleSafely() throws Exception { DefaultNodeHandler handler = new DefaultNodeHandler(); assertTrue(handler.handle(node, emitter)); verifyNoMoreInteractions(emitter); }
YamlEmitter { public void writeValue(SimpleTypeNode<?> node) throws IOException { if (node instanceof StringNode) { writeQuoted(node.getLiteralValue()); } else { writeNaked(node.getLiteralValue()); } } YamlEmitter(); YamlEmitter(Writer writer, int i); YamlEmitter indent(); YamlEmitter bulletListArray(); void writeTag(...
@Test public void writeValueClean() throws Exception { when(stringNode.getLiteralValue()).thenReturn("hello"); YamlEmitter emitter = new YamlEmitter(writer, 0); emitter.writeValue(stringNode); assertEquals("hello", writer.toString()); } @Test public void writeValue() throws Exception { when(stringNode.getLiteralValue()...
AllResourceSelector implements Selector<Resource> { @Override public FluentIterable<Resource> fromApi(Api api) { List<Resource> topResources = api.resources(); FluentIterable<Resource> fi = from(topResources); for (Resource resource : topResources) { fi = fi.append(fromResource(resource)); } return fi; } @Override Flu...
@Test public void fromApi() throws Exception { when(api.resources()).thenReturn(Collections.singletonList(resource)); when(resource.resources()).thenReturn(Collections.singletonList(subResource)); AllResourceSelector allResourceSelector = new AllResourceSelector(); FluentIterable<Resource> apiElements = allResourceSele...
AllResourceSelector implements Selector<Resource> { @Override public FluentIterable<Resource> fromResource(Resource topResource) { List<Resource> resources = topResource.resources(); FluentIterable<Resource> fi = from(resources); for (Resource resource : resources) { fi = fi.append(fromResource(resource)); } return fi;...
@Test public void fromResource() throws Exception { when(resource.resources()).thenReturn(Collections.singletonList(subResource)); AllResourceSelector allResourceSelector = new AllResourceSelector(); FluentIterable<Resource> apiElements = allResourceSelector.fromResource(resource); assertThat(apiElements, containsInAny...
ApiQueryBaseHandler implements QueryBase { @Override public <B> FluentIterable<B> queryFor(Selector<B> selector) { return selector.fromApi(api); } ApiQueryBaseHandler(Api api); @Override FluentIterable<B> queryFor(Selector<B> selector); }
@Test public void queryFor() throws Exception { when(selector.fromApi(api)).thenReturn(fluentIterator); ApiQueryBaseHandler handler = new ApiQueryBaseHandler(api); FluentIterable<Resource> iterable = handler.queryFor(selector); assertNotNull(iterable); verify(selector).fromApi(api); }
RamlTypeFactory { public static Optional<RamlType> forType(Type type, final ClassParser parser, final AdjusterFactory adjusterFactory) { if ( type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; if ( Collection.class.isAssignableFrom((Class)parameterizedType.getRawType())...
@Test public void forArrayOfComposed() throws Exception { when(adjusterFactory.createAdjuster(SubFun.class)).thenReturn(RamlAdjuster.NULL_ADJUSTER); RamlType type = RamlTypeFactory.forType(Fun.class.getDeclaredField("arrayOfSubs").getGenericType(), null, adjusterFactory).orNull(); assertTrue(type instanceof CollectionR...
ResourceQueryBaseHandler implements QueryBase { @Override public <B> FluentIterable<B> queryFor(Selector<B> selector) { return selector.fromResource(resource); } ResourceQueryBaseHandler(Resource resource); @Override FluentIterable<B> queryFor(Selector<B> selector); }
@Test public void queryFor() throws Exception { when(selector.fromResource(resource)).thenReturn(fluentIterator); ResourceQueryBaseHandler handler = new ResourceQueryBaseHandler(resource); FluentIterable<Resource> iterable = handler.queryFor(selector); assertNotNull(iterable); verify(selector).fromResource(resource); }
TopResourceSelector implements Selector<Resource> { @Override public FluentIterable<Resource> fromApi(Api api) { return from(api.resources()); } @Override FluentIterable<Resource> fromApi(Api api); @Override FluentIterable<Resource> fromResource(Resource resource); }
@Test public void fromApi() throws Exception { TopResourceSelector topResourceSelector = new TopResourceSelector(); FluentIterable<Resource> apiElements = topResourceSelector.fromApi(api); assertEquals(0, apiElements.size()); verify(api).resources(); }
TopResourceSelector implements Selector<Resource> { @Override public FluentIterable<Resource> fromResource(Resource resource) { return FluentIterable.from(resource.resources()); } @Override FluentIterable<Resource> fromApi(Api api); @Override FluentIterable<Resource> fromResource(Resource resource); }
@Test public void fromResource() throws Exception { TopResourceSelector topResourceSelector = new TopResourceSelector(); FluentIterable<Resource> resourceElements = topResourceSelector.fromResource(resource); assertEquals(0, resourceElements.size()); verify(resource).resources(); }
Query { public<T> FluentIterable<T> select(Selector<T> selector) { return queryBase.queryFor(selector); } Query(QueryBase queryBase); static Query from(Api api); static Query from(Resource resource); FluentIterable<T> select(Selector<T> selector); }
@Test public void select() throws Exception { when(base.queryFor(selector)).thenReturn(fluentList); Query query = new Query(base); FluentIterable<Resource> resourceList = query.select(selector); assertSame(resourceList, fluentList); }
ResultingPojos { public void createAllTypes(String rootDirectory) throws IOException { generationContext.createSupportTypes(rootDirectory); for (CreationResult result : results) { result.createType(rootDirectory); } generationContext.createTypes(rootDirectory); } ResultingPojos(GenerationContextImpl generationContext);...
@Test public void createAllTypes() throws Exception { ResultingPojos pojos = new ResultingPojos(generationContext); pojos.addNewResult(result); pojos.createAllTypes("/tmp/fun"); verify(generationContext).createTypes("/tmp/fun"); verify(generationContext).createSupportTypes("/tmp/fun"); verify(result).createType("/tmp/f...
ResultingPojos { public void createFoundTypes(String rootDirectory) throws IOException { generationContext.createSupportTypes(rootDirectory); for (CreationResult result : results) { result.createType(rootDirectory); } } ResultingPojos(GenerationContextImpl generationContext); void addNewResult(CreationResult spec); Lis...
@Test public void createFoundTypes() throws Exception { ResultingPojos pojos = new ResultingPojos(generationContext); pojos.addNewResult(result); pojos.createFoundTypes("/tmp/fun"); verify(result).createType("/tmp/fun"); verify(generationContext).createSupportTypes("/tmp/fun"); verify(generationContext, never()).create...
GenerationContextImpl implements GenerationContext { public void setupTypeHierarchy(String actualName, TypeDeclaration typeDeclaration) { List<TypeDeclaration> parents = typeDeclaration.parentTypes(); for (TypeDeclaration parent : parents) { setupTypeHierarchy(parent.name(), parent); if ( ! parent.name().equals(actualN...
@Test public void setupTypeHierarchy() { when(type1.parentTypes()).thenReturn(Arrays.<TypeDeclaration>asList(type2, type3)); when(type2.parentTypes()).thenReturn(Arrays.<TypeDeclaration>asList(type3, type4)); when(type1.name()).thenReturn("type1"); when(type2.name()).thenReturn("type2"); when(type3.name()).thenReturn("...
EnumerationTypeHandler implements TypeHandler { @Override public Optional<CreationResult> create(GenerationContext generationContext, CreationResult preCreationResult) { Class cls = (typeDeclaration instanceof StringTypeDeclaration)?String.class:Number.class; FieldSpec.Builder field = FieldSpec.builder(ClassName.get(cl...
@Test public void createString() throws Exception { when(stringDeclaration.name()).thenReturn("Days"); when(stringDeclaration.enumValues()).thenReturn(Arrays.asList("one", "two", "three")); EnumerationTypeHandler handler = new EnumerationTypeHandler("days", stringDeclaration); GenerationContextImpl generationContext = ...
UnionTypeHandler implements TypeHandler { private TypeSpec.Builder getImplementation(ClassName interfaceName, GenerationContext generationContext, UnionPluginContext context, CreationResult preCreationResult) { TypeSpec.Builder typeSpec = TypeSpec.classBuilder(preCreationResult.getJavaName(EventType.IMPLEMENTATION)) .a...
@Test public void datesUnion() throws Exception { Api api = RamlLoader.load(this.getClass().getResourceAsStream("union-dates.raml"), "."); RamlToPojo ramlToPojo = new RamlToPojoBuilder(api).fetchTypes(TypeFetchers.fromAnywhere()).findTypes(TypeFinders.everyWhere()).build(Arrays.asList("core.jackson2")); ramlToPojo.buil...
Annotations { public T get(T def, Annotable type) { return getValueWithDefault(def, type); } static R evaluate(Function<TypeInstance, T> convert, String annotationName, String parameterName, Annotable mandatory, Annotable... others); static List<R> evaluateAsList(Function<TypeInstance, T> convert, String annotationNam...
@Test public void apiAnnotationsReading() throws IOException { Api api = getApi(); List<PluginDef> defs = Annotations.PLUGINS.get(api); assertEquals(2, defs.size()); assertEquals("core.one", defs.get(0).getPluginName()); assertEquals(Arrays.asList("foo", "bar"), defs.get(0).getArguments()); assertEquals("core.two", def...
ObjectTypeHandler implements TypeHandler { @Override public Optional<CreationResult> create(GenerationContext generationContext, CreationResult result) { ObjectPluginContext context = new ObjectPluginContextImpl(generationContext, result); TypeSpec interfaceSpec = createInterface(context, result, generationContext); Ty...
@Test public void simplest() throws Exception { Api api = RamlLoader.load(this.getClass().getResourceAsStream("simplest-type.raml"), "."); ObjectTypeHandler handler = new ObjectTypeHandler("foo", RamlLoader.findTypes("foo", api.types())); GenerationContextImpl generationContext = new GenerationContextImpl(api); Creatio...
CreationResult { public void createType(String rootDirectory) throws IOException { if ( interf.typeSpecs.size() == 0 ) { createInlineType(this); } createJavaFile(packageName, interf, rootDirectory, true); if ( implementationName != null ) { createJavaFile(packageName, impl, rootDirectory, false); } } CreationResult(Str...
@Test public void createType() throws Exception { CreationResult result = new CreationResult("pack.me", ClassName.get("", "foo"), ClassName.get("", "foo")) { TypeSpec[] specs = {interf, cls}; int c = 0; @Override protected void createJavaFile(String pack, TypeSpec spec, String root, boolean b) { assertEquals("pack.me",...
Names { public static String typeName(String... name) { if (name.length == 1 && isBlank(name[0])) { return "Root"; } List<String> values = new ArrayList<>(); int i = 0; for (String s : name) { String value = buildPart(i, s, NameFixer.CAMEL_UPPER); values.add(value); i++; } return Joiner.on("").join(values); } private ...
@Test public void buildTypeName() throws Exception { assertEquals("Fun", Names.typeName("/fun")); assertEquals("Fun", Names.typeName("/fun")); assertEquals("CodeBytes", Names.typeName(" assertEquals("Root", Names.typeName("")); assertEquals("FunAllo", Names.typeName("fun_allo")); assertEquals("FunAllo", Names.typeName(...
Names { public static String methodName(String... name) { return checkMethodName(smallCamel(name)); } private Names(); static String typeName(String... name); static String methodName(String... name); static String variableName(String... name); static String constantName(String value); static String enumName(String va...
@Test public void buildMethod() { assertEquals("getSomething", Names.methodName("get", "something")); assertEquals("getClazz", Names.methodName("get", "class")); }
Names { public static String variableName(String... name) { Matcher m = LEADING_UNDERSCORES.matcher(name[0]); if (m.find()) { return m.group() + smallCamel(name); } else { return checkForReservedWord(smallCamel(name)); } } private Names(); static String typeName(String... name); static String methodName(String... name...
@Test public void buildVariableName() throws Exception { assertEquals("funAllo", Names.variableName("funAllo")); assertEquals("funAllo", Names.variableName("FunAllo")); assertEquals("funAllo", Names.variableName("Fun", "allo")); assertEquals("funAllo", Names.variableName("fun", "_allo")); assertEquals("funAllo", Names....
PojoToRamlImpl implements PojoToRaml { @Override public Result classToRaml(final Class<?> clazz) { RamlType type = RamlTypeFactory.forType(clazz, classParserFactory.createParser(clazz), adjusterFactory).or(new RamlTypeSupplier(clazz)); if ( type.isScalar()) { return new Result(null, Collections.<String, TypeDeclaration...
@Test public void scalarType() throws Exception { PojoToRamlImpl pojoToRaml = new PojoToRamlImpl(FieldClassParser.factory(), AdjusterFactory.NULL_FACTORY); Result types = pojoToRaml.classToRaml(String.class); Api api = createApi(types); List<TypeDeclaration> buildTypes = api.types(); assertEquals(0, buildTypes.size());...
RenamePlugin extends AllTypesPluginHelper { @Override public ClassName className(ObjectPluginContext objectPluginContext, ObjectTypeDeclaration ramlType, ClassName currentSuggestion, EventType eventType) { return changeName(currentSuggestion, eventType); } RenamePlugin(List<String> arguments); @Override ClassName class...
@Test public void className() { RenamePlugin plugin = new RenamePlugin(Arrays.asList("One", "OneImplementation")); ClassName cn = plugin.className((ObjectPluginContext) null, null, ClassName.bestGuess("fun.com.Allo"), EventType.INTERFACE); assertEquals("fun.com.One", cn.toString()); cn = plugin.className((ObjectPluginC...
BoxWhenNotRequired implements ReferenceTypeHandlerPlugin { @Override public TypeName typeName(ReferencePluginContext referencePluginContext, TypeDeclaration ramlType, TypeName currentSuggestion) { if (! ramlType.required()) { return currentSuggestion.box(); } else { return currentSuggestion; } } BoxWhenNotRequired(List...
@Test public void boxOnNotRequired() { when(integerDeclaration.required()).thenReturn(false); BoxWhenNotRequired boxWhenNotRequired = new BoxWhenNotRequired(null); TypeName tn = boxWhenNotRequired.typeName(null, integerDeclaration, TypeName.INT); assertEquals(TypeName.INT.box(), tn); } @Test public void noBoxOnRequired...
JaxbUnionExtension implements UnionTypeHandlerPlugin { @Override public ClassName className(UnionPluginContext unionPluginContext, UnionTypeDeclaration ramlType, ClassName currentSuggestion, EventType eventType) { return currentSuggestion; } @Override ClassName className(UnionPluginContext unionPluginContext, UnionTyp...
@Test public void className() { JaxbUnionExtension jaxb = new JaxbUnionExtension(); ClassName typeName = ClassName.bestGuess("foo.Union"); TypeName calculatedTypeName = jaxb.className(null, null, typeName, null); assertSame(typeName, calculatedTypeName); }
JaxbUnionExtension implements UnionTypeHandlerPlugin { @Override public TypeSpec.Builder classCreated(UnionPluginContext unionPluginContext, UnionTypeDeclaration type, TypeSpec.Builder builder, EventType eventType) { String namespace = type.xml() != null && type.xml().namespace() != null ? type.xml().namespace() : "##d...
@Test public void classCreated() { JaxbUnionExtension jaxb = new JaxbUnionExtension(); TypeSpec.Builder classBuilder = TypeSpec.classBuilder("my.BuiltClass"); TypeSpec.Builder builder = jaxb.classCreated(null, unionTypeDeclaration, classBuilder, EventType.INTERFACE); TypeSpec buildClass = builder.build(); TypeSpecAsser...
JaxbUnionExtension implements UnionTypeHandlerPlugin { @Override public FieldSpec.Builder anyFieldCreated(UnionPluginContext context, UnionTypeDeclaration union, TypeSpec.Builder typeSpec, FieldSpec.Builder anyType, EventType eventType) { AnnotationSpec.Builder elementsAnnotation = AnnotationSpec.builder(XmlElements.cl...
@Test public void anyFieldCreated() { }
Jsr303Extension extends AllTypesPluginHelper { @Override public FieldSpec.Builder fieldBuilt(ObjectPluginContext objectPluginContext, TypeDeclaration typeDeclaration, FieldSpec.Builder fieldSpec, EventType eventType) { AnnotationAdder adder = new AnnotationAdder() { @Override public TypeName typeName() { return fieldSp...
@Test public void forInteger() throws Exception { setupNumberFacets(); Jsr303Extension ext = new Jsr303Extension(); FieldSpec.Builder builder = FieldSpec.builder(ClassName.get(Integer.class), "champ", Modifier.PUBLIC); ext.fieldBuilt(objectPluginContext, number, builder, EventType.IMPLEMENTATION); assertForIntegerNumbe...
PojoToRamlImpl implements PojoToRaml { @Override public TypeBuilder name(Class<?> clazz) { RamlAdjuster adjuster = this.adjusterFactory.createAdjuster(clazz); ClassParser parser = classParserFactory.createParser(clazz); RamlType type = RamlTypeFactory.forType(clazz, parser, adjusterFactory).or(new RamlTypeSupplier(claz...
@Test public void name() throws Exception { PojoToRamlImpl pojoToRaml = new PojoToRamlImpl(FieldClassParser.factory(), AdjusterFactory.NULL_FACTORY); TypeBuilder builder = pojoToRaml.name(Fun.class.getMethod("stringMethod").getGenericReturnType()); ObjectNode node = builder.buildNode(); assertEquals("type: array", node...
Jsr303Extension extends AllTypesPluginHelper { @Override public FieldSpec.Builder anyFieldCreated( UnionPluginContext context, UnionTypeDeclaration union, TypeSpec.Builder typeSpec, FieldSpec.Builder anyType, EventType eventType) { FacetValidation.addFacetsForBuilt(new AnnotationAdder() { @Override public TypeName type...
@Test public void forUnion() throws Exception { Jsr303Extension ext = new Jsr303Extension(); TypeSpec.Builder typeBuilder = TypeSpec.classBuilder(ClassName.get("xx.bb", "Foo")); FieldSpec.Builder builder = FieldSpec.builder(ClassName.get(Double.class), "champ", Modifier.PUBLIC); ext.anyFieldCreated(unionPluginContext, ...
ArrayTypeHandler implements TypeHandler { @Override public TypeName javaClassReference(GenerationContext generationContext, EventType type) { if ( name.contains("[") || name.equals("array")) { String itemTypeName = typeDeclaration.items().name(); if ("object".equals(itemTypeName)) { itemTypeName = typeDeclaration.items...
@Test public void javaClassReferenceWithString() { when(referencePlugin.typeName(any(ReferencePluginContext.class), any(TypeDeclaration.class), eq(ParameterizedTypeName.get(List.class, String.class)))).thenReturn(ParameterizedTypeName.get(List.class, String.class)); when(referencePlugin.typeName(any(ReferencePluginCont...
TypeFetchers { public static TypeFetcher fromTypes() { return new TypeFetcher() { Iterable<TypeDeclaration> foundInApi; @Override public TypeDeclaration fetchType(Api api, final String name) throws GenerationException { return FluentIterable.from(Optional.fromNullable(foundInApi).or(api.types())) .firstMatch(namedPredi...
@Test public void fromTypes() throws Exception { when(api.types()).thenReturn(Arrays.asList(t1, t2, t3)); TypeDeclaration typeDeclaration = TypeFetchers.fromTypes().fetchType(api, "t1"); assertSame(t1, typeDeclaration); } @Test(expected = GenerationException.class) public void fromTypesFail() throws Exception { when(ap...
TypeFetchers { public static TypeFetcher fromLibraries() { return new TypeFetcher() { Iterable<TypeDeclaration> foundInApi; @Override public TypeDeclaration fetchType(Api api, final String name) throws GenerationException { return FluentIterable.from(Optional.fromNullable(foundInApi).or(Utils.goThroughLibraries(new Arr...
@Test public void fromLibraries() throws Exception { when(api.uses()).thenReturn(Arrays.asList(l1, l2)); when(l1.uses()).thenReturn(Collections.singletonList(l3)); when(l1.types()).thenReturn(Collections.singletonList(t1)); when(l2.types()).thenReturn(Collections.singletonList(t2)); when(l3.types()).thenReturn(Collecti...
TypeFetchers { public static TypeFetcher fromAnywhere() { return new TypeFetcher() { Iterable<TypeDeclaration> foundInApi; @Override public TypeDeclaration fetchType(Api api, final String name) throws GenerationException { return FluentIterable.from(Optional.fromNullable(foundInApi).or(FluentIterable.from(api.types())....
@Test public void fromAnywhere() throws Exception { when(api.types()).thenReturn(Arrays.asList(t4, t5, t6)); when(api.uses()).thenReturn(Arrays.asList(l1, l2)); when(l1.uses()).thenReturn(Collections.singletonList(l3)); when(l1.types()).thenReturn(Collections.singletonList(t1)); when(l2.types()).thenReturn(Collections....
TypeFinders { public static TypeFinder inTypes() { return new TypeFinder() { @Override public Iterable<TypeDeclaration> findTypes(Api api) { return api.types(); } }; } static TypeFinder inTypes(); static TypeFinder inLibraries(); static TypeFinder everyWhere(); static TypeFinder inResources(); }
@Test public void inTypes() { when(api.types()).thenReturn(Arrays.asList(t1, t2, t3)); Iterable<TypeDeclaration> it = TypeFinders.inTypes().findTypes(api); assertThat(it, contains(equalTo(t1), equalTo(t2), equalTo(t3))); }
TypeFinders { public static TypeFinder inLibraries() { return new TypeFinder() { @Override public Iterable<TypeDeclaration> findTypes(Api api) { List<TypeDeclaration> foundTypes = new ArrayList<>(); Utils.goThroughLibraries(foundTypes, new HashSet<String>(), api.uses()); return foundTypes; } }; } static TypeFinder inT...
@Test public void inLibraries() { when(api.uses()).thenReturn(Arrays.asList(l1, l2)); when(l1.uses()).thenReturn(Collections.singletonList(l3)); when(l1.types()).thenReturn(Collections.singletonList(t1)); when(l2.types()).thenReturn(Collections.singletonList(t2)); when(l3.types()).thenReturn(Collections.singletonList(t...
TypeFinders { public static TypeFinder everyWhere() { return new TypeFinder() { @Override public Iterable<TypeDeclaration> findTypes(Api api) { return FluentIterable.from(api.types()) .append(resourceTypes(api.resources())) .append(Utils.goThroughLibraries(new ArrayList<TypeDeclaration>(), new HashSet<String>(), api.us...
@Test public void everyWhere() { when(api.types()).thenReturn(Arrays.asList(t4, t5, t6)); when(api.uses()).thenReturn(Arrays.asList(l1, l2)); when(l1.uses()).thenReturn(Collections.singletonList(l3)); when(l1.types()).thenReturn(Collections.singletonList(t1)); when(l2.types()).thenReturn(Collections.singletonList(t2));...
Augmenter { public static<T> T augment(Class<T> augmentedInterface, final Object delegate) { try { Extension extension = augmentedInterface.getAnnotation(Extension.class); ExtensionFactory extensionFactory = augmentedInterface.getAnnotation(ExtensionFactory.class); if ( extension == null && extensionFactory == null ) {...
@Test public void simple() throws Exception { Foo foo = (Foo) Proxy.newProxyInstance(AugmenterTest.class.getClassLoader(), new Class[] {Foo.class}, new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { return method.getName(); } }); Boo b = Augmenter.aug...
ResponseBuilder extends KeyValueNodeBuilder<ResponseBuilder> implements NodeBuilder, AnnotableBuilder<ResponseBuilder> { static public ResponseBuilder response(int code) { return new ResponseBuilder(code); } private ResponseBuilder(int code); static ResponseBuilder response(int code); ResponseBuilder withBodies(BodyBu...
@Test public void response() { Api api = document() .baseUri("http: .title("doc") .version("one") .mediaType("foo/fun") .withResources( resource("/foo") .withMethods(MethodBuilder.method("get") .withResponses(ResponseBuilder.response(200) .withBodies(BodyBuilder.body("application/json").ofType(TypeBuilder.type("integer...
ResourceBuilder extends KeyValueNodeBuilder<ResourceBuilder> implements NodeBuilder { private ResourceBuilder(String name) { super(name); } private ResourceBuilder(String name); static ResourceBuilder resource(String name); @Override KeyValueNode buildNode(); ResourceBuilder displayName(String displayName); ResourceBu...
@Test public void resourceBuilder() { Api api = document() .baseUri("http: .title("doc") .version("one") .mediaType("foo/fun") .withResources( resource("/foo") .description("happy") ) .buildModel(); assertEquals("/foo", api.resources().get(0).displayName().value()); assertEquals("/foo", api.resources().get(0).resourceP...
TypeBuilder extends ObjectNodeBuilder<TypeBuilder> implements NodeBuilder, AnnotableBuilder<TypeBuilder> { static public TypeBuilder type(String type) { return new TypeBuilder(type); } private TypeBuilder(String type); TypeBuilder(String[] types); TypeBuilder(TypeBuilder builder); String id(); static TypeBuilder typ...
@Test public void simpleType() { Api api = document() .baseUri("http: .title("doc") .version("one") .mediaType("foo/fun") .withTypes( TypeDeclarationBuilder.typeDeclaration("Mom") .ofType(TypeBuilder.type("boolean"))) .buildModel(); assertEquals("Mom", api.types().get(0).name()); assertEquals("boolean", api.types().get...
Emitter { public void emit(Api api) throws IOException { emit(api, new OutputStreamWriter(System.out)); } Emitter(HandlerList list); Emitter(); void emit(Api api); void emit(Api api, Writer w); }
@Test public void emit() throws Exception { when(api.getNode()).thenReturn(node); when(node.getChildren()).thenReturn(Arrays.asList(child1, child2)); Emitter emitter = new Emitter(list) { @Override protected YamlEmitter createEmitter(Writer w) { assertSame(w, writer); return yamlEmitter; } }; emitter.emit(api, writer);...
HandlerList extends NodeHandler<Node> { @Override public boolean handles(final Node node) { return FluentIterable.from(handlerList).anyMatch(new Predicate<NodeHandler<? extends Node>>() { @Override public boolean apply(@Nullable NodeHandler<? extends Node> nodeHandler) { return nodeHandler.handles(node); } }); } Handle...
@Test public void handles() throws Exception { when(nodeHandler1.handles(node)).thenReturn(true); HandlerList list = new HandlerList(Arrays.<NodeHandler<? extends Node>>asList(nodeHandler1, nodeHandler2)); assertTrue(list.handles(node)); verify(nodeHandler2, never()).handles(any(Node.class)); } @Test public void handle...
ReferenceNodeHandler extends NodeHandler<ReferenceNode> { @Override public boolean handles(Node node) { return node instanceof ReferenceNode; } @Override boolean handles(Node node); @Override boolean handleSafely(ReferenceNode node, YamlEmitter emitter); }
@Test public void handles() throws Exception { ReferenceNodeHandler handler = new ReferenceNodeHandler(); assertFalse(handler.handles(badNode)); assertTrue(handler.handles(goodNode)); }
ReferenceNodeHandler extends NodeHandler<ReferenceNode> { @Override public boolean handleSafely(ReferenceNode node, YamlEmitter emitter) throws IOException { emitter.writeObjectValue(node.getRefName()); return true; } @Override boolean handles(Node node); @Override boolean handleSafely(ReferenceNode node, YamlEmitter ...
@Test public void handleSafely() throws Exception { when(goodNode.getRefName()).thenReturn("ref.value"); ReferenceNodeHandler rnh = new ReferenceNodeHandler(); rnh.handleSafely(goodNode, emitter); verify(emitter).writeObjectValue("ref.value"); }
TypeDeclarationNodeHandler extends NodeHandler<TypeDeclarationNode> { @Override public boolean handles(Node node) { return node instanceof TypeDeclarationNode; } TypeDeclarationNodeHandler(HandlerList handlerList); @Override boolean handles(Node node); @Override boolean handleSafely(TypeDeclarationNode node, YamlEmitte...
@Test public void handles() throws Exception { TypeDeclarationNodeHandler tdnh = new TypeDeclarationNodeHandler(list); assertFalse(tdnh.handles(badNode)); assertTrue(tdnh.handles(goodNode)); }
TypeDeclarationNodeHandler extends NodeHandler<TypeDeclarationNode> { @Override public boolean handleSafely(TypeDeclarationNode node, YamlEmitter emitter) throws IOException { for (Node child : node.getChildren()) { handlerList.handle(child, emitter); } return true; } TypeDeclarationNodeHandler(HandlerList handlerList)...
@Test public void handleSafely() throws Exception { when(goodNode.getChildren()).thenReturn(Collections.<Node>singletonList(keyValueNode)); TypeDeclarationNodeHandler handler = new TypeDeclarationNodeHandler(list); handler.handleSafely(goodNode, emitter); verify(list).handle(keyValueNode, emitter); }
ArrayNodeHandler extends NodeHandler<ArrayNode> { @Override public boolean handles(Node node) { return node instanceof ArrayNode; } ArrayNodeHandler(HandlerList handlerList); @Override boolean handles(Node node); @Override boolean handleSafely(ArrayNode node, YamlEmitter emitter); }
@Test public void handles() throws Exception { ArrayNodeHandler handler = new ArrayNodeHandler(list); assertFalse(handler.handles(badNode)); assertTrue(handler.handles(goodNode)); }
ArrayNodeHandler extends NodeHandler<ArrayNode> { @Override public boolean handleSafely(ArrayNode node, YamlEmitter emitter) throws IOException { List<Node> children = node.getChildren(); if ( childrenAreAllScalarTypes(children)) { emitter.writeSyntaxElement("["); for (int a = 0; a < children.size(); a++) { handlerList...
@Test public void handleSafelyEmpty() throws Exception { ArrayNodeHandler handler = new ArrayNodeHandler(list); handler.handleSafely(goodNode, emitter); verify(emitter).writeSyntaxElement("["); verify(emitter).writeSyntaxElement("]"); verifyNoMoreInteractions(emitter); } @Test public void handleSafelyTwoScalarElements(...
KeyValueNodeHandler extends NodeHandler<KeyValueNode> { @Override public boolean handles(Node node) { return node instanceof KeyValueNode; } KeyValueNodeHandler(HandlerList handlerList); @Override boolean handles(Node node); @Override boolean handleSafely(KeyValueNode node, YamlEmitter emitter); }
@Test public void handles() throws Exception { KeyValueNodeHandler handler = new KeyValueNodeHandler(list); assertFalse(handler.handles(notKeyNode)); assertTrue(handler.handles(keyNode)); }
KeyValueNodeHandler extends NodeHandler<KeyValueNode> { @Override public boolean handleSafely(KeyValueNode node, YamlEmitter emitter) throws IOException { String scalar = isScalar(node.getValue()); if ( scalar != null ) { emitter.writeTag(node.getKey().toString()); handlerList.handle(node.getValue(), emitter); } else {...
@Test public void handleSafelyScalar() throws Exception { when(keyNode.getValue()).thenReturn(simpleNode); when(keyNode.getKey()).thenReturn(new StringNodeImpl("hello")); KeyValueNodeHandler handler = new KeyValueNodeHandler(list); assertTrue(handler.handleSafely(keyNode, emitter)); verify(emitter).writeTag("hello"); v...
SubclassedNodeHandler extends NodeHandler<T> { @Override public boolean handle(Node node, YamlEmitter emitter) { try { return subclassHandlerList.handle(node, emitter) || handleSafely((T) node, emitter); } catch (IOException e) { throw new RuntimeException(e); } } SubclassedNodeHandler(Class<?> superClass, HandlerList ...
@Test public void fallsThrough() throws Exception { when(subNodeHandler.handle(node, emitter)).thenReturn(false); SubclassedNodeHandler<ObjectNode> on = new SubclassedNodeHandler<ObjectNode>(ObjectNode.class, subNodeHandler) { @Override public boolean handleSafely(ObjectNode node, YamlEmitter emitter) throws IOExceptio...
TypeExpressionNodeHandler extends SubclassedNodeHandler<TypeExpressionNode> { @Override public boolean handles(Node node) { return node instanceof TypeExpressionNode; } TypeExpressionNodeHandler(HandlerList handlerList); @Override boolean handles(Node node); @Override boolean handleSafely(TypeExpressionNode node, YamlE...
@Test public void handles() throws Exception { TypeExpressionNodeHandler handler = new TypeExpressionNodeHandler(list); assertFalse(handler.handles(badNode)); assertTrue(handler.handles(goodNode)); }
TypeExpressionNodeHandler extends SubclassedNodeHandler<TypeExpressionNode> { @Override public boolean handleSafely(TypeExpressionNode node, YamlEmitter emitter) throws IOException { List<LibraryRefNode> descs = node.findDescendantsWith(LibraryRefNode.class); if ( descs.size() != 0 && descs.get(0) != null ) { emitter.w...
@Test public void handleSafely() throws Exception { when(goodNode.getTypeExpressionText()).thenReturn("JustReference"); TypeExpressionNodeHandler handler = new TypeExpressionNodeHandler(list); handler.handle(goodNode, emitter); verify(emitter).writeObjectValue("JustReference"); }
ObjectNodeHandler extends SubclassedNodeHandler<ObjectNode> { @Override public boolean handleSafely(ObjectNode node, YamlEmitter emitter) throws IOException { for (Node child : node.getChildren()) { String scalar = isScalar(node.getChildren().get(0)); if ( scalar != null ) { emitter.writeObjectValue(scalar); } else { h...
@Test public void handleSafely() throws Exception { when(objectNode.getChildren()).thenReturn(Collections.<Node>singletonList(child)); ObjectNodeHandler on = new ObjectNodeHandler(list); on.handleSafely(objectNode, emitter); verify(list).handle(child, emitter); } @Test public void handleSafelyScalar() throws Exception ...
NullNodeHandler extends NodeHandler<NullNode> { @Override public boolean handles(Node node) { return node instanceof NullNode; } NullNodeHandler(); @Override boolean handles(Node node); @Override boolean handleSafely(NullNode node, YamlEmitter emitter); }
@Test public void handles() throws Exception { NullNodeHandler handler = new NullNodeHandler(); assertFalse(handler.handles(notNullNode)); assertTrue(handler.handles(nullNode)); }
NullNodeHandler extends NodeHandler<NullNode> { @Override public boolean handleSafely(NullNode node, YamlEmitter emitter) throws IOException { return true; } NullNodeHandler(); @Override boolean handles(Node node); @Override boolean handleSafely(NullNode node, YamlEmitter emitter); }
@Test public void handleSafely() throws Exception { NullNodeHandler nul = new NullNodeHandler(); nul.handleSafely(nullNode, emitter); verifyNoMoreInteractions(emitter); }
SimpleTypeNodeHandler extends NodeHandler<SimpleTypeNode<?>> { @Override public boolean handles(Node node) { return node instanceof SimpleTypeNode; } SimpleTypeNodeHandler(); @Override boolean handles(Node node); @Override boolean handleSafely(SimpleTypeNode<?> node, YamlEmitter emitter); }
@Test public void handles() throws Exception { SimpleTypeNodeHandler handler = new SimpleTypeNodeHandler(); assertFalse(handler.handles(badNode)); assertTrue(handler.handles(goodNode)); }
Highlight extends UserNote implements Comparable<Highlight> { @NonNull public static ArrayList<ContentValues> deserializeToContentValues(@NonNull String serialized, PageInfo pageInfo, int bookId) { Matcher matcher = HIGHLIGHT_PATTERN.matcher(serialized); if (matcher.matches()) { String[] serializedHighlights = serializ...
@Test public void deserializeGeneric() throws Exception { ArrayList<ContentValues> highlightsReturn = Highlight.deserializeToContentValues(serialized1,pagId,0); ArrayList<ContentValues> highlightsGiven = new ArrayList<>(); ContentValues contentValues = new ContentValues(); contentValues.put(UserDataDBContract.Highlight...
Highlight extends UserNote implements Comparable<Highlight> { @NonNull public static ArrayList<Highlight> deserialize(@NonNull String serialized, PageInfo pageInfo, int bookId) { final Pattern pattern = Pattern.compile("^type:(\\w+)(?:\\|(\\d+)\\$(\\d+)\\$(\\d+)\\$(\\w+)\\$(\\d*)\\$([^|]+))+$"); Matcher matcher = patte...
@Test public void deserialize() throws Exception { ArrayList<Highlight> highlightsRerurn = Highlight.deserialize(serialized1,pagId,0); ArrayList<Highlight> highlightsGiven = new ArrayList<>(); highlightsGiven.add(new Highlight("dcdcdc ", 2, "highlight3", 0, pagId, "note",0)); highlightsGiven.add(new Highlight("cdcdc ",...
ArabicUtilities { public static String handleTatweela(@NonNull String s) { Matcher matcher4 = TATWEELA_PATTERN.matcher(s); StringBuffer sb2 = new StringBuffer(); while (matcher4.find()) { matcher4.appendReplacement(sb2, "$1$3"); } matcher4.appendTail(sb2); return sb2.toString(); } static String cleanTashkeel(@NonNull ...
@Test public void handleTatweela() throws Exception { assertEquals(ArabicUtilities.handleTatweela("بـــــــــــــــــــسم"), "بسم"); assertEquals(ArabicUtilities.handleTatweela("هـ"), "هـ"); }
ArabicUtilities { public static String cleanTextForSearchingIndexing(String s) { return cleanTextForSearchingQuery(cleanHtml(s)); } static String cleanTashkeel(@NonNull String s); static String cleanTextForSearchingIndexing(String s); @NonNull static String cleanTextForSearchingQuery(@NonNull String s); static String ...
@Test public void cleanTextForSearchingIndexing() throws Exception { assertEquals(ArabicUtilities.cleanTextForSearchingIndexing(testCase), "هذا المستدرك ثم بعد ان جمعت فتاوي ورسائل مفتي الديار السعوديه ورئيس قضائها والشئون الاسلاميه سماحه الشيخ محمد بن ابراهيم ال الشيخ بامر جلاله الملك فيصل بن عبد العزيز ال سعود رحمه ا...
ArabicUtilities { @NonNull public static String cleanHtml(String htmlText) { Document doc = Jsoup.parse(htmlText); Elements footnotes = doc.select("a[title].comment"); StringBuilder htmlTextBuilder = new StringBuilder(htmlText); for (Element footnote : footnotes) { htmlTextBuilder.append("\n").append(footnote.attr("tit...
@Test public void cleanHtml() throws Exception { assertEquals(ArabicUtilities.cleanHtml(testCase), "هذا المستدرك\nثم بعد أن جمعت فتاوى ورسائل مفتي الديار السعودية ورئيس قضائها والشئون الإسلامية سماحة الشيخ محمد بن إبراهيم آل الشيخ بأمر جلالة الملك فيصل بن عبد العزيز آل سعود رحمه الله وطبعت في مطبعة الحكومة بمكة المكرمة...
ArabicUtilities { public static String cleanTashkeel(@NonNull String s) { Matcher matcher = CLEANING_TASHKEEL.matcher(s); return matcher.replaceAll(""); } static String cleanTashkeel(@NonNull String s); static String cleanTextForSearchingIndexing(String s); @NonNull static String cleanTextForSearchingQuery(@NonNull St...
@Test public void cleanTashkeel() throws Exception { String testStringWithTashkeel = "فَكَمْ نَدْ رَأَيْنَا مِنْ رِجَالٍ وَدَوْلَةٍ ... فَبَادُوا جَمِيعًا مُسْرِعِينَ وَزَالُوا"; String testStringWithTashkeel2 = "خِلَافٌ يَصِحُّ تَخْرِيجُهُ عَلَى هَذِهِ الْقَاعِدَةِ لِأَنَّ قَوْلَهُ حَرَامٌ مُطْلَقٌ دَالٌّ عَلَى مُطْلَ...
ArabicUtilities { @NonNull public static String cleanTextForSearchingWthStingBuilder(String s) { StringBuilder sb = new StringBuilder(s); for (int i = 0; i < sb.length(); i++) { char c = sb.charAt(i); if ((c < HAMZAH || c > YEH) & !Character.isSpace(c)) { sb.deleteCharAt(i); i--; } else if (Character.isSpace(c)) { sb.s...
@Test public void cleanTextForSearchingWthStingBuilder() throws Exception { }
ArabicUtilities { public static boolean startsWithDefiniteArticle(@NonNull String string) { return string.startsWith("ال"); } static String cleanTashkeel(@NonNull String s); static String cleanTextForSearchingIndexing(String s); @NonNull static String cleanTextForSearchingQuery(@NonNull String s); static String handle...
@Test public void startsWithDefiniteArticle() throws Exception { assertEquals(ArabicUtilities.startsWithDefiniteArticle("البخاري"), true); assertEquals(ArabicUtilities.startsWithDefiniteArticle("اللبن"), true); assertEquals(ArabicUtilities.startsWithDefiniteArticle("اللحم"), true); }
ConfigHelper { public static ConfigHelper fromFile(String file) throws IOException { return new ConfigHelper(file); } ConfigHelper(); ConfigHelper(Properties properties); @Inject ConfigHelper(List<ConfigHelper> configuration); private ConfigHelper(String configFilename); private ConfigHelper(File configFile); priva...
@Test public void testFromFile() throws IOException { ConfigHelper helper = ConfigHelper.fromFile("src/test/resources/base-config.properties"); Assert.assertEquals("Base Property 1", helper.getRaw("prop1")); Assert.assertEquals("Base Property 2", helper.getRaw("prop2")); }
PropertyTypeValidator implements ConfigHelperValidator { @Override public void validate(ConfigHelper configHelper) throws RuntimeException { for (String propertyName : configHelper.getPropertyNames()) { Class<?> desiredType = configHelper.getPropertyType(propertyName); if (desiredType == null) { continue; } if (desired...
@Test public void shouldSkipValidationOfUnreferencedProperties() { Properties properties = new Properties(); properties.put("property", "false"); ConfigHelper configHelper = new ConfigHelper(properties); PropertyTypeValidator validator = new PropertyTypeValidator(null, null); validator.validate(configHelper); } @Test p...
JpaMetamodelRedGProvider implements NameProvider, DataTypeProvider { @Override public String getClassNameForTable(Table table) { ManagedType managedType = managedTypesByTableName.get(table.getName().toUpperCase()); return managedType != null ? managedType.getJavaType().getSimpleName() : fallbackNameProvider.getClassNam...
@Test public void testGetClassNameForTable() throws Exception { Assert.assertEquals("ManagedSuperClassJoined", provider.getClassNameForTable(getTable("MANAGEDSUPERCLASSJOINED"))); Assert.assertEquals("SubEntityJoined1", provider.getClassNameForTable(getTable("SUB_ENTITY_JOINED_1"))); Assert.assertEquals("SubEntityJoine...
RedGBuilder { public T build() { final T inst = instance; instance = null; return inst; } @SuppressWarnings("unchecked") RedGBuilder(); RedGBuilder(final Class<T> clazz); RedGBuilder<T> withDefaultValueStrategy(final DefaultValueStrategy strategy); RedGBuilder<T> withPreparedStatementParameterSetter(final PreparedSta...
@Test public void testBuilder_ClassPrivate() { expectedException.expect(RuntimeException.class); expectedException.expectMessage("Could not instantiate RedG instance"); AbstractRedG redG = new RedGBuilder<>(PrivateRedG.class).build(); } @Test public void testBuilder_DefaultConstructor() throws Exception { try { Abstrac...
DefaultDummyFactory implements DummyFactory { @Override public <T extends RedGEntity> T getDummy(final AbstractRedG redG, final Class<T> dummyClass) { if (this.dummyCache.containsKey(dummyClass)) { return dummyClass.cast(this.dummyCache.get(dummyClass)); } final T obj = createNewDummy(redG, dummyClass); this.dummyCache...
@Test public void testGetDummy_reuseCachedObject() throws Exception { AbstractRedG redG = spy(AbstractRedG.class); DefaultDummyFactory factory = new DefaultDummyFactory(); assertNotNull(factory); TestRedGEntity1 entity1 = factory.getDummy(redG, TestRedGEntity1.class); assertNotNull(entity1); TestRedGEntity1 entity2 = f...
RedGDatabaseUtil { public static void insertDataIntoDatabase(List<? extends RedGEntity> gObjects, final Connection connection) { insertDataIntoDatabase(gObjects, connection, new DefaultPreparedStatementParameterSetter()); } private RedGDatabaseUtil(); static void insertDataIntoDatabase(List<? extends RedGEntity> gObje...
@Test public void testInsertDataIntoDatabase() throws Exception { Connection connection = getConnection("-idid"); Statement stmt = connection.createStatement(); stmt.execute("CREATE TABLE TEST (CONTENT VARCHAR2(50 CHAR))"); List<MockEntity1> gObjects = IntStream.rangeClosed(1, 20).mapToObj(i -> new MockEntity1()).colle...
XmlFileDataTypeProvider implements DataTypeProvider { String getDataTypeByName(String tableName, String columnName) { if (typeMappings.getTableTypeMappings() == null) { return null; } return typeMappings.getTableTypeMappings().stream() .filter(tableTypeMapping -> tableName.matches(tableTypeMapping.getTableName())) .fla...
@Test public void testGetDataTypeByName() throws Exception { TypeMappings typeMappings = new TypeMappings(); typeMappings.setTableTypeMappings(Arrays.asList( new TableTypeMapping(".+", Collections.singletonList(new ColumnTypeMapping("ACTIVE", "java.lang.Boolean"))), new TableTypeMapping("JOIN_TABLE", Collections.single...
EntitySorter { public static List<RedGEntity> sortEntities(List<RedGEntity> entities) { Map<RedGEntity, Integer> depths = new DepthCalculator().calculateDepths(entities); return entities.stream() .sorted(Comparator.comparing(EntitySorter::isExisting).reversed().thenComparingInt(depths::get)) .collect(Collectors.toList(...
@Test public void entitiesAreSortedByDepths() throws Exception { EntitySorter entitySorter = new EntitySorter(); Entity leafEntity1 = new Entity("leafEntity1"); Entity leafEntity2 = new Entity("leafEntity2"); Entity leafEntity3 = new Entity("leafEntity3"); Entity nonLeaf1 = new Entity("nonLeaf1", leafEntity1, leafEntit...
DataExtractor { public void setSqlSchemaName(String sqlSchemaName) { this.sqlSchemaName = sqlSchemaName; } JavaCodeRepresentationProvider getJcrProvider(); void setJcrProvider(final JavaCodeRepresentationProvider jcrProvider); Function<EntityModel, EntityInclusionMode> getEntityModeDecider(); void setEntityModeDecider...
@Test public void testGetFullSqlName() throws Exception { final TableModel tm1 = new TableModel(); tm1.setSqlFullName("TEST.TABLE"); assertThat(wrapGetFullTableName(new DataExtractor(), tm1)).isEqualTo("TEST.TABLE"); final TableModel tm2 = new TableModel(); tm2.setSqlFullName("TEST.\"TABLE\""); assertThat(wrapGetFullTa...
TableModelExtractor { public static List<TableModel> extractTableModelsFromSourceCode(final Path srcDir, final String packageName, final String classPrefix) throws IOException, ClassNotFoundException { LOG.debug("Starting table model extraction from source code..."); final List<TableModel> results = new ArrayList<>(); ...
@Test @Ignore public void extractTableModelsFromSourceCode() throws Exception { TableModelExtractor.extractTableModelsFromSourceCode(Paths.get("D:\\redg\\redg-playground\\target\\generated-test-sources\\redg"), "com.btc.redg.generated", "G"); }
TableModelExtractor { public static List<TableModel> extractTableModelFromClasses(final Path classDir, final String packageName, final String classPrefix) throws IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { LOG.debug("Starting table model extraction fro...
@Test @Ignore public void extractTableModelFromClasses() throws Exception { TableModelExtractor.extractTableModelFromClasses(Paths.get("D:\\redg\\redg-playground\\target\\test-classes"), "com.btc.redg.generated", "G"); }
XmlFileDataTypeProvider implements DataTypeProvider { String getDataTypeBySqlType(final Column column) { if (typeMappings.getDefaultTypeMappings() == null) { return null; } List<String> variants = DataTypePrecisionHelper.getDataTypeWithAllPrecisionVariants(column); return variants.stream() .map(variant -> typeMappings....
@Test public void testGetDataTypeBySqlName() throws Exception { TypeMappings typeMappings = new TypeMappings(); typeMappings.setDefaultTypeMappings(Arrays.asList( new DefaultTypeMapping("DECIMAL", "java.lang.Long"), new DefaultTypeMapping("DECIMAL(1)", "java.lang.Boolean"), new DefaultTypeMapping(" TIMESTAMP WITH TIME ...