use of org.jpox.samples.one_one.unidir_2.Reader in project swagger-core by swagger-api.
the class JaxrsApplicationAndResourcePackagesAnnotationScannerTest method shouldScanOnlyApplicationClasses.
@Test(description = "scan classes from Application")
public void shouldScanOnlyApplicationClasses() throws Exception {
SwaggerConfiguration config = new SwaggerConfiguration().openAPI(new OpenAPI().info(new Info().description("TEST INFO DESC")));
Application application = new Application() {
@Override
public Set<Class<?>> getClasses() {
return Collections.singleton(ResourceInPackageA.class);
}
};
OpenApiContext ctx = new GenericOpenApiContext<>().openApiConfiguration(config).openApiReader(new Reader(config)).openApiScanner(scanner.application(application).openApiConfiguration(config)).init();
OpenAPI openApi = ctx.read();
assertNotNull(openApi);
assertEquals(openApi.getPaths().keySet(), Arrays.asList("/packageA"));
}
use of org.jpox.samples.one_one.unidir_2.Reader in project swagger-core by swagger-api.
the class JaxrsApplicationAndResourcePackagesAnnotationScannerTest method shouldScanOnlyResourcePackagesClasses.
@Test(description = "scan classes from resource packages only")
public void shouldScanOnlyResourcePackagesClasses() throws Exception {
SwaggerConfiguration config = new SwaggerConfiguration().resourcePackages(Stream.of("com.my.project.resources", "org.my.project.resources").collect(Collectors.toSet())).openAPI(new OpenAPI().info(new Info().description("TEST INFO DESC")));
OpenApiContext ctx = new GenericOpenApiContext<>().openApiConfiguration(config).openApiReader(new Reader(config)).openApiScanner(new JaxrsApplicationAndResourcePackagesAnnotationScanner().openApiConfiguration(config)).init();
OpenAPI openApi = ctx.read();
assertNotNull(openApi);
assertEquals(openApi.getPaths().keySet(), Arrays.asList("/packageA", "/packageB"));
}
use of org.jpox.samples.one_one.unidir_2.Reader in project tests by datanucleus.
the class RelationshipTest method test1to1UnidirInheritanceSubclassTable.
/**
* Test case for 1-1 bidirectional relationships using 2 FK's.
* This is really tested as BasicQuery and DatastoreId test.
*/
/*public void test1to1BidirectionalMultiFK()
throws Exception
{
try
{
Object idUser = null;
Object idUserDetail = null;
PersistenceManager pm=pmf.getPersistenceManager();
Transaction tx=pm.currentTransaction();
// Create sample data
try
{
tx.begin();
User user=new User("andy","password");
UserDetails details=new UserDetails("Andy","Jefferson");
user.setDetails(details);
details.setUser(user);
pm.makePersistent(user);
tx.commit();
idUser = pm.getObjectId(user);
idUserDetail = pm.getObjectId(details);
}
catch (Exception e)
{
LOG.error(e);
fail("Exception thrown while creating 1-1 bidirectional relationship data : " + e.getMessage());
}
finally
{
if (tx.isActive())
{
tx.rollback();
}
pm.close();
}
pm=pmf.getPersistenceManager();
tx=pm.currentTransaction();
// Create sample data
try
{
tx.begin();
User user=(User)pm.getObjectById(idUser,true);
UserDetails details=(UserDetails)pm.getObjectById(idUserDetail,true);
assertEquals(details,user.getUserDetails());
assertEquals(user,details.getUser());
tx.commit();
}
catch (Exception e)
{
LOG.error(e);
fail("Exception thrown while creating 1-1 bidirectional relationship data : " + e.getMessage());
}
finally
{
if (tx.isActive())
{
tx.rollback();
}
pm.close();
}
}
finally
{
clean(User.class);
clean(UserDetails.class);
}
}*/
/**
* Test case for 1-1 uni relationship to a class using "subclass-table" inheritance strategy. See JIRA "NUCRDBMS-18"
*/
public void test1to1UnidirInheritanceSubclassTable() throws Exception {
try {
// Create the necessary schema
try {
addClassesToSchema(new Class[] { Newspaper.class, Magazine.class, MediaWork.class, Reader.class });
} catch (Exception e) {
e.printStackTrace();
fail("Exception thrown while adding classes for 1-1 relation using subclass-table : " + e.getMessage());
}
// Check the persistence of data
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object fredId = null;
Object pamId = null;
try {
tx.begin();
Magazine hello = new Magazine("Hello", MediaWork.FREQ_WEEKLY, "Trash Publishers");
Newspaper mail = new Newspaper("Daily Mail", MediaWork.FREQ_DAILY, "Piers Morgan", "Tabloid");
Reader fred = new Reader("Fred Smith", mail);
Reader pam = new Reader("Pam Green", hello);
pm.makePersistent(fred);
pm.makePersistent(pam);
tx.commit();
fredId = pm.getObjectId(fred);
pamId = pm.getObjectId(pam);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
// Check the retrieval of the data
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
Reader fred = (Reader) pm.getObjectById(fredId, true);
assertTrue("Fred has the wrong name!", fred.getName().equals("Fred Smith"));
assertTrue("Fred has the wrong type of material", fred.getMaterial() instanceof Newspaper);
assertTrue("Fred has the wrong material", fred.getMaterial().getName().equals("Daily Mail"));
Reader pam = (Reader) pm.getObjectById(pamId, true);
assertTrue("Pam has the wrong name", pam.getName().equals("Pam Green"));
assertTrue("Pam has the wrong type of material", pam.getMaterial() instanceof Magazine);
assertTrue("Pam has the wrong material", pam.getMaterial().getName().equals("Hello"));
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
// Check a query
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
Query q1 = pm.newQuery(Reader.class, "((org.jpox.samples.one_one.unidir_2.Magazine)material).name == \"Hello\"");
List results1 = (List) q1.execute();
assertEquals("Number of readers who read \"Hello\" magazine was incorrect", results1.size(), 1);
Query q2 = pm.newQuery(Reader.class, "((org.jpox.samples.one_one.unidir_2.Newspaper)material).name == \"Daily Mail\"");
List results2 = (List) q2.execute();
assertEquals("Number of readers who read \"Daily Mail\" newspaper was incorrect", results2.size(), 1);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
// Clean out all data
clean(Reader.class);
clean(Newspaper.class);
clean(Magazine.class);
}
}
use of org.jpox.samples.one_one.unidir_2.Reader in project swagger-core by swagger-api.
the class JaxrsOpenApiContext method buildReader.
@Override
protected OpenApiReader buildReader(OpenAPIConfiguration openApiConfiguration) throws Exception {
OpenApiReader reader;
if (StringUtils.isNotBlank(openApiConfiguration.getReaderClass())) {
Class cls = getClass().getClassLoader().loadClass(openApiConfiguration.getReaderClass());
reader = (OpenApiReader) cls.newInstance();
} else {
reader = new Reader();
}
if (reader instanceof Reader) {
((Reader) reader).setApplication(app);
}
reader.setConfiguration(openApiConfiguration);
return reader;
}
use of org.jpox.samples.one_one.unidir_2.Reader in project swagger-core by swagger-api.
the class AbstractAnnotationTest method readIntoYaml.
public String readIntoYaml(final Class<?> cls) {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(cls);
try {
Yaml.mapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
// parse JSON
JsonNode jsonNodeTree = Yaml.mapper().readTree(Yaml.mapper().writeValueAsString(openAPI));
// return it as YAML
return Yaml.mapper().writeValueAsString(jsonNodeTree);
} catch (Exception e) {
return "Empty YAML";
}
}
Aggregations