Search in sources :

Example 1 with RuleDTO

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

the class AutoProxCatalogResource method getRule.

@ApiOperation(value = "Retrieve a single AutoProx rule", response = RuleDTO.class)
@ApiResponses({ @ApiResponse(code = 404, message = "No rule by the specified name"), @ApiResponse(code = 200, message = "Rule spec sent") })
@GET
@Path("{name}")
public Response getRule(@PathParam("name") final String name) {
    Response response = checkEnabled();
    if (response != null) {
        return response;
    }
    final RuleDTO dto = controller.getRule(name);
    if (dto == null) {
        return Response.status(Status.NOT_FOUND).build();
    } else {
        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) RuleDTO(org.commonjava.indy.autoprox.rest.dto.RuleDTO) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with RuleDTO

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

the class AbstractAutoproxCalculatorTest method installRule.

protected RuleDTO installRule(final String named, final String ruleScriptResource) throws IOException, IndyClientException {
    final URL resource = Thread.currentThread().getContextClassLoader().getResource(ruleScriptResource);
    if (resource == null) {
        Assert.fail("Cannot find classpath resource: " + ruleScriptResource);
    }
    final String spec = IOUtils.toString(resource);
    return client.module(AutoProxCatalogModule.class).storeRule(new RuleDTO(named, spec));
}
Also used : AutoProxCatalogModule(org.commonjava.indy.autoprox.client.AutoProxCatalogModule) RuleDTO(org.commonjava.indy.autoprox.rest.dto.RuleDTO) URL(java.net.URL)

Example 3 with RuleDTO

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

the class AbstractAutoproxDeletionTest method installRule.

protected RuleDTO installRule(final String named, final String ruleScriptResource) throws IOException, IndyClientException {
    final URL resource = Thread.currentThread().getContextClassLoader().getResource(ruleScriptResource);
    if (resource == null) {
        Assert.fail("Cannot find classpath resource: " + ruleScriptResource);
    }
    String spec = IOUtils.toString(resource);
    spec = spec.replace("@baseUri@", http.getBaseUri());
    return client.module(AutoProxCatalogModule.class).storeRule(new RuleDTO(named, spec));
}
Also used : AutoProxCatalogModule(org.commonjava.indy.autoprox.client.AutoProxCatalogModule) RuleDTO(org.commonjava.indy.autoprox.rest.dto.RuleDTO) URL(java.net.URL)

Example 4 with RuleDTO

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

the class CreateRuleFailsWhenAutoProxDisabledTest method createRuleAndVerifyListingReflectsIt.

@Test(expected = IndyClientException.class)
public void createRuleAndVerifyListingReflectsIt() throws Exception {
    final RuleDTO rule = getRule("0001-simple-rule", "rules/simple-rule.groovy");
    final RuleDTO dto = module.storeRule(rule);
}
Also used : RuleDTO(org.commonjava.indy.autoprox.rest.dto.RuleDTO) Test(org.junit.Test)

Example 5 with RuleDTO

use of org.commonjava.indy.autoprox.rest.dto.RuleDTO 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)

Aggregations

RuleDTO (org.commonjava.indy.autoprox.rest.dto.RuleDTO)12 Test (org.junit.Test)5 ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponse (io.swagger.annotations.ApiResponse)4 Response (javax.ws.rs.core.Response)4 CatalogDTO (org.commonjava.indy.autoprox.rest.dto.CatalogDTO)4 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)4 ApiResponses (io.swagger.annotations.ApiResponses)3 URL (java.net.URL)3 Path (javax.ws.rs.Path)3 AutoProxRuleException (org.commonjava.indy.autoprox.data.AutoProxRuleException)3 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)2 IOException (java.io.IOException)2 URI (java.net.URI)2 Consumes (javax.ws.rs.Consumes)2 AutoProxCatalogModule (org.commonjava.indy.autoprox.client.AutoProxCatalogModule)2 File (java.io.File)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1