This repository has been archived by the owner on May 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Beans annotated only and refactor injection
- Loading branch information
Showing
25 changed files
with
365 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
catalog-core/src/main/java/uk/gov/justice/schema/catalog/CatalogProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package uk.gov.justice.schema.catalog; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Produces; | ||
|
||
@ApplicationScoped | ||
public class CatalogProducer { | ||
|
||
@Produces | ||
public Catalog catalog() { | ||
return new ObjectFactory().catalog(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
catalog-core/src/main/java/uk/gov/justice/schema/catalog/ObjectFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package uk.gov.justice.schema.catalog; | ||
|
||
import uk.gov.justice.schema.catalog.util.ClasspathResourceLoader; | ||
import uk.gov.justice.schema.catalog.util.UriResolver; | ||
import uk.gov.justice.schema.catalog.util.UrlConverter; | ||
import uk.gov.justice.services.common.converter.jackson.ObjectMapperProducer; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class ObjectFactory { | ||
|
||
public UrlConverter urlConverter() { | ||
return new UrlConverter(); | ||
} | ||
|
||
public ObjectMapper objectMapper() { | ||
return new ObjectMapperProducer().objectMapper(); | ||
} | ||
|
||
public UriResolver uriResolver() { | ||
return new UriResolver(); | ||
} | ||
|
||
public JsonStringToSchemaConverter jsonStringToSchemaConverter() { | ||
return new JsonStringToSchemaConverter(); | ||
} | ||
|
||
public ClasspathResourceLoader classpathResourceLoader() { | ||
return new ClasspathResourceLoader(); | ||
} | ||
|
||
public ClasspathCatalogLoader classpathCatalogLoader() { | ||
final ClasspathCatalogLoader classpathCatalogLoader = new ClasspathCatalogLoader(); | ||
classpathCatalogLoader.objectMapper = objectMapper(); | ||
classpathCatalogLoader.classpathResourceLoader = classpathResourceLoader(); | ||
classpathCatalogLoader.urlConverter = urlConverter(); | ||
|
||
return classpathCatalogLoader; | ||
} | ||
|
||
public SchemaResolver schemaResolver() { | ||
final SchemaResolver schemaResolver = new SchemaResolver(); | ||
schemaResolver.urlConverter = urlConverter(); | ||
schemaResolver.uriResolver = uriResolver(); | ||
return schemaResolver; | ||
} | ||
|
||
public CatalogToSchemaResolver catalogToSchemaResolver() { | ||
final CatalogToSchemaResolver catalogToSchemaResolver = new CatalogToSchemaResolver(); | ||
catalogToSchemaResolver.classpathCatalogLoader = classpathCatalogLoader(); | ||
catalogToSchemaResolver.schemaResolver = schemaResolver(); | ||
catalogToSchemaResolver.logger = LoggerFactory.getLogger(CatalogToSchemaResolver.class); | ||
|
||
return catalogToSchemaResolver; | ||
} | ||
|
||
public FileContentsAsStringLoader fileContentsAsStringLoader() { | ||
return new FileContentsAsStringLoader(); | ||
} | ||
|
||
public JsonSchemaFileLoader jsonSchemaFileLoader() { | ||
final JsonSchemaFileLoader jsonSchemaFileLoader = new JsonSchemaFileLoader(); | ||
jsonSchemaFileLoader.fileContentsAsStringLoader = fileContentsAsStringLoader(); | ||
jsonSchemaFileLoader.catalogToSchemaResolver = catalogToSchemaResolver(); | ||
|
||
return jsonSchemaFileLoader; | ||
} | ||
|
||
public SchemaClientFactory schemaClientFactory() { | ||
return new SchemaClientFactory(); | ||
} | ||
|
||
public Catalog catalog() { | ||
final Catalog catalog = new Catalog(); | ||
catalog.rawCatalog = rawCatalog(); | ||
catalog.schemaClientFactory = schemaClientFactory(); | ||
catalog.jsonStringToSchemaConverter = jsonStringToSchemaConverter(); | ||
|
||
return catalog; | ||
} | ||
|
||
public RawCatalog rawCatalog() { | ||
final RawCatalog rawCatalog = new RawCatalog(); | ||
rawCatalog.jsonSchemaFileLoader = jsonSchemaFileLoader(); | ||
rawCatalog.initialize(); | ||
return rawCatalog; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
catalog-core/src/main/java/uk/gov/justice/schema/catalog/SchemaClientFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
catalog-core/src/test/java/uk/gov/justice/schema/catalog/CatalogProducerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package uk.gov.justice.schema.catalog; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.notNullValue; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class CatalogProducerTest { | ||
|
||
@InjectMocks | ||
private CatalogProducer catalogProducer; | ||
|
||
@Test | ||
public void shouldCreateTheCatalog() throws Exception { | ||
|
||
final Catalog catalog = catalogProducer.catalog(); | ||
|
||
assertThat(catalog, is(notNullValue())); | ||
|
||
assertThat(getPrivateField(catalog, "rawCatalog", RawCatalog.class), is(notNullValue())); | ||
assertThat(getPrivateField(catalog, "schemaClientFactory", SchemaClientFactory.class), is(notNullValue())); | ||
assertThat(getPrivateField(catalog, "jsonStringToSchemaConverter", JsonStringToSchemaConverter.class), is(notNullValue())); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private <T> T getPrivateField(final Catalog catalog, final String fieldName, @SuppressWarnings("unused") final Class<T> clazz) throws Exception { | ||
|
||
final Field field = catalog.getClass().getDeclaredField(fieldName); | ||
field.setAccessible(true); | ||
return (T) field.get(catalog); | ||
} | ||
} |
Oops, something went wrong.