Search in sources :

Example 6 with Reader

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"));
}
Also used : Reader(io.swagger.v3.jaxrs2.Reader) GenericOpenApiContext(io.swagger.v3.oas.integration.GenericOpenApiContext) Info(io.swagger.v3.oas.models.info.Info) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Application(javax.ws.rs.core.Application) SwaggerConfiguration(io.swagger.v3.oas.integration.SwaggerConfiguration) GenericOpenApiContext(io.swagger.v3.oas.integration.GenericOpenApiContext) OpenApiContext(io.swagger.v3.oas.integration.api.OpenApiContext) Test(org.testng.annotations.Test)

Example 7 with Reader

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"));
}
Also used : Reader(io.swagger.v3.jaxrs2.Reader) GenericOpenApiContext(io.swagger.v3.oas.integration.GenericOpenApiContext) Info(io.swagger.v3.oas.models.info.Info) OpenAPI(io.swagger.v3.oas.models.OpenAPI) SwaggerConfiguration(io.swagger.v3.oas.integration.SwaggerConfiguration) GenericOpenApiContext(io.swagger.v3.oas.integration.GenericOpenApiContext) OpenApiContext(io.swagger.v3.oas.integration.api.OpenApiContext) Test(org.testng.annotations.Test)

Example 8 with Reader

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);
    }
}
Also used : Newspaper(org.jpox.samples.one_one.unidir_2.Newspaper) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) Reader(org.jpox.samples.one_one.unidir_2.Reader) List(java.util.List) ArrayList(java.util.ArrayList) JDOObjectNotFoundException(javax.jdo.JDOObjectNotFoundException) Magazine(org.jpox.samples.one_one.unidir_2.Magazine)

Example 9 with Reader

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;
}
Also used : Reader(io.swagger.v3.jaxrs2.Reader) OpenApiReader(io.swagger.v3.oas.integration.api.OpenApiReader) OpenApiReader(io.swagger.v3.oas.integration.api.OpenApiReader)

Example 10 with 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";
    }
}
Also used : Reader(io.swagger.v3.jaxrs2.Reader) JsonNode(com.fasterxml.jackson.databind.JsonNode) OpenAPI(io.swagger.v3.oas.models.OpenAPI) IOException(java.io.IOException)

Aggregations

Reader (io.swagger.v3.jaxrs2.Reader)11 OpenAPI (io.swagger.v3.oas.models.OpenAPI)10 Test (org.testng.annotations.Test)8 GenericOpenApiContext (io.swagger.v3.oas.integration.GenericOpenApiContext)4 SwaggerConfiguration (io.swagger.v3.oas.integration.SwaggerConfiguration)4 OpenApiContext (io.swagger.v3.oas.integration.api.OpenApiContext)4 Info (io.swagger.v3.oas.models.info.Info)4 AbstractAnnotationTest (io.swagger.v3.jaxrs2.annotations.AbstractAnnotationTest)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ReaderListenerResource (io.swagger.v3.jaxrs2.resources.ReaderListenerResource)1 Parameter (io.swagger.v3.oas.annotations.Parameter)1 OpenApiReader (io.swagger.v3.oas.integration.api.OpenApiReader)1 PathItem (io.swagger.v3.oas.models.PathItem)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JDOObjectNotFoundException (javax.jdo.JDOObjectNotFoundException)1 PersistenceManager (javax.jdo.PersistenceManager)1 Query (javax.jdo.Query)1 Transaction (javax.jdo.Transaction)1