Search in sources :

Example 1 with CatalogDTO

use of org.commonjava.indy.autoprox.rest.dto.CatalogDTO in project indy by Commonjava.

the class AutoProxCatalogResource method getCatalog.

@ApiOperation(value = "Retrieve the AutoProx rule catalog", response = CatalogDTO.class)
@ApiResponses({ @ApiResponse(code = 404, message = "AutoProx is disabled or no rules are defined."), @ApiResponse(code = 200, message = "Catalog sent") })
@GET
@Produces(ApplicationContent.application_json)
public Response getCatalog() {
    Response response = checkEnabled();
    if (response != null) {
        return response;
    }
    final CatalogDTO dto = controller.getCatalog();
    if (dto == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    return formatOkResponseWithJsonEntity(dto, serializer);
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) CatalogDTO(org.commonjava.indy.autoprox.rest.dto.CatalogDTO) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with CatalogDTO

use of org.commonjava.indy.autoprox.rest.dto.CatalogDTO in project indy by Commonjava.

the class ListExistingCatalogTest method listDefaultCatalog.

@Test
public void listDefaultCatalog() throws Exception {
    try {
        final CatalogDTO catalog = module.getCatalog();
        assertThat(catalog.isEnabled(), equalTo(true));
    } catch (Exception e) {
        logger.error("Test error", e);
        throw e;
    }
}
Also used : CatalogDTO(org.commonjava.indy.autoprox.rest.dto.CatalogDTO) Test(org.junit.Test)

Example 3 with CatalogDTO

use of org.commonjava.indy.autoprox.rest.dto.CatalogDTO in project indy by Commonjava.

the class CreateAndVerifyRuleTest method createRuleAndVerifyRetrieval.

@Test
public void createRuleAndVerifyRetrieval() throws Exception {
    final CatalogDTO catalog = module.getCatalog();
    assertThat(catalog.isEnabled(), equalTo(true));
    assertThat(catalog.getRules().isEmpty(), equalTo(true));
    final RuleDTO rule = getRule("0001-simple-rule", "rules/simple-rule.groovy");
    final RuleDTO dto = module.storeRule(rule);
    assertThat(dto, notNullValue());
    assertThat(dto, equalTo(rule));
}
Also used : CatalogDTO(org.commonjava.indy.autoprox.rest.dto.CatalogDTO) RuleDTO(org.commonjava.indy.autoprox.rest.dto.RuleDTO) Test(org.junit.Test)

Example 4 with CatalogDTO

use of org.commonjava.indy.autoprox.rest.dto.CatalogDTO in project indy by Commonjava.

the class CreateAndDeleteRuleTest method createRuleDeleteAndVerifyMissing.

@Test
public void createRuleDeleteAndVerifyMissing() throws Exception {
    final CatalogDTO catalog = module.getCatalog();
    assertThat(catalog.isEnabled(), equalTo(true));
    assertThat(catalog.getRules().isEmpty(), equalTo(true));
    final RuleDTO rule = getRule("0001-simple-rule", "rules/simple-rule.groovy");
    RuleDTO dto = module.storeRule(rule);
    assertThat(dto, notNullValue());
    assertThat(dto, equalTo(rule));
    module.deleteRuleNamed(dto.getName());
    dto = module.getRuleNamed(dto.getName());
    assertThat(dto, nullValue());
}
Also used : CatalogDTO(org.commonjava.indy.autoprox.rest.dto.CatalogDTO) RuleDTO(org.commonjava.indy.autoprox.rest.dto.RuleDTO) Test(org.junit.Test)

Example 5 with CatalogDTO

use of org.commonjava.indy.autoprox.rest.dto.CatalogDTO in project indy by Commonjava.

the class ReparsePicksUpNewRuleFileTest method writeRuleFileThenReparseCatalogAndVerifyRulePresence.

@Test
public void writeRuleFileThenReparseCatalogAndVerifyRulePresence() throws Exception {
    final CatalogDTO catalog = module.getCatalog();
    assertThat(catalog.isEnabled(), equalTo(true));
    assertThat(catalog.getRules().isEmpty(), equalTo(true));
    final RuleDTO rule = getRule("0001-simple-rule.groovy", "rules/simple-rule.groovy");
    final File script = new File(fixture.getBootOptions().getIndyHome(), "var/lib/indy/data/autoprox/0001-simple-rule.groovy");
    FileUtils.write(script, rule.getSpec());
    module.reparseCatalog();
    final CatalogDTO resultCatalog = module.getCatalog();
    final List<RuleDTO> rules = resultCatalog.getRules();
    assertThat(rules.size(), equalTo(1));
    final RuleDTO dto = rules.get(0);
    assertThat(dto.getName(), equalTo(FilenameUtils.removeExtension(rule.getName())));
    assertThat(dto.getSpec(), equalTo(rule.getSpec()));
}
Also used : CatalogDTO(org.commonjava.indy.autoprox.rest.dto.CatalogDTO) RuleDTO(org.commonjava.indy.autoprox.rest.dto.RuleDTO) File(java.io.File) Test(org.junit.Test)

Aggregations

CatalogDTO (org.commonjava.indy.autoprox.rest.dto.CatalogDTO)6 Test (org.junit.Test)5 RuleDTO (org.commonjava.indy.autoprox.rest.dto.RuleDTO)4 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ApiResponses (io.swagger.annotations.ApiResponses)1 File (java.io.File)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)1