javax.validation.UnexpectedTypeException Java Examples

The following examples show how to use javax.validation.UnexpectedTypeException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApiTransformationConfig.java    From api-layer with Eclipse Public License 2.0 6 votes vote down vote up
@Bean
@Scope(value = "prototype")
public AbstractApiDocService abstractApiDocService(String content) {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    try {
        ObjectNode objectNode = mapper.readValue(content, ObjectNode.class);
        JsonNode openApiNode = objectNode.get("openapi");
        if (openApiNode != null) {
            return new ApiDocV3Service(gatewayClient);
        } else {
            JsonNode swaggerNode = objectNode.get("swagger");
            if (swaggerNode != null) {
                return new ApiDocV2Service(gatewayClient);
            }
        }
    } catch (IOException e) {
        log.debug("Could not convert response body to a Swagger/OpenAPI object.", e);
        throw new UnexpectedTypeException("Response is not a Swagger or OpenAPI type object.");
    }

    return null;
}
 
Example #2
Source File: MinLengthTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class MinLengthTargetBean {

        @MinLength(5)
        public Object value;
    }
    MinLengthTargetBean target = new MinLengthTargetBean();
    VALIDATOR.validate(target);
}
 
Example #3
Source File: NumberTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class NumberTargetBean {

        @Number(precision = 2)
        public Object value;
    }
    NumberTargetBean target = new NumberTargetBean();
    VALIDATOR.validate(target);
}
 
Example #4
Source File: MaxSizeTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class MaxSizeTargetBean {

        @MaxSize(5)
        public Object value;
    }
    MaxSizeTargetBean target = new MaxSizeTargetBean();
    VALIDATOR.validate(target);
}
 
Example #5
Source File: AlphabetTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class AlphabetTargetBean {

        @Alphabet
        public Object value;
    }
    AlphabetTargetBean target = new AlphabetTargetBean();
    VALIDATOR.validate(target);
}
 
Example #6
Source File: FixedAfterEqualsToTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class FixedAfterEqualsToTargetBean {

        @FixedAfterEqualsTo("2013/07/04")
        public Object value;
    }
    FixedAfterEqualsToTargetBean target = new FixedAfterEqualsToTargetBean();
    VALIDATOR.validate(target);
}
 
Example #7
Source File: FixedGreaterThanTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class FixedGreaterThanTargetBean {

        @FixedGreaterThan("0.5")
        public Object value;
    }
    FixedGreaterThanTargetBean target = new FixedGreaterThanTargetBean();
    VALIDATOR.validate(target);
}
 
Example #8
Source File: ZenkakuTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class ZenkakuTargetBean {

        @Zenkaku
        public Object value;
    }
    ZenkakuTargetBean target = new ZenkakuTargetBean();
    VALIDATOR.validate(target);
}
 
Example #9
Source File: FixedBeforeEqualsToTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class FixedBeforeEqualsToTargetBean {

        @FixedBeforeEqualsTo("2013/07/05")
        public Object value;
    }
    FixedBeforeEqualsToTargetBean target = new FixedBeforeEqualsToTargetBean();
    VALIDATOR.validate(target);
}
 
Example #10
Source File: MaxByteLengthTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class MaxByteLengthTargetBean {

        @MaxByteLength(100)
        public Object value;
    }
    MaxByteLengthTargetBean target = new MaxByteLengthTargetBean();
    VALIDATOR.validate(target);
}
 
Example #11
Source File: NumericFormatTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class NumericFormatTargetBean {

        @NumericFormat
        public Object value;
    }
    NumericFormatTargetBean target = new NumericFormatTargetBean();
    VALIDATOR.validate(target);
}
 
Example #12
Source File: HiraganaTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class HiraganaTargetBean {

        @Hiragana
        public Object value;
    }
    HiraganaTargetBean target = new HiraganaTargetBean();
    VALIDATOR.validate(target);
}
 
Example #13
Source File: DecimalTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class DecimalTargetBean {

        @Decimal(precision = 2, scale = 0)
        public Object value;
    }
    DecimalTargetBean target = new DecimalTargetBean();
    VALIDATOR.validate(target);
}
 
Example #14
Source File: CreditCardTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class CreditCardTargetBean {

        @CreditCard(value = Type.VISA)
        public Object value;
    }
    CreditCardTargetBean target = new CreditCardTargetBean();
    VALIDATOR.validate(target);
}
 
Example #15
Source File: KatakanaTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class KatakanaTargetBean {

        @Katakana
        public Object value;
    }
    KatakanaTargetBean target = new KatakanaTargetBean();
    VALIDATOR.validate(target);
}
 
Example #16
Source File: ZipCodeTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class ZipCodeTargetBean {

        @ZipCode
        public Object value;
    }
    ZipCodeTargetBean target = new ZipCodeTargetBean();
    VALIDATOR.validate(target);
}
 
Example #17
Source File: EqualsLengthTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class EqualsLengthTargetBean {

        @EqualsLength(100)
        public Object value;
    }
    EqualsLengthTargetBean target = new EqualsLengthTargetBean();
    VALIDATOR.validate(target);
}
 
Example #18
Source File: EqualsByteLengthTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class EqualsByteLengthTargetBean {

        @EqualsByteLength(value = 100)
        public Object value;
    }
    EqualsByteLengthTargetBean target = new EqualsByteLengthTargetBean();
    VALIDATOR.validate(target);
}
 
Example #19
Source File: FixedLessThanEqualsToTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class FixedLessThanEqualsToTargetBean {

        @FixedLessThanEqualsTo("0.5")
        public Object value;
    }
    FixedLessThanEqualsToTargetBean target = new FixedLessThanEqualsToTargetBean();
    VALIDATOR.validate(target);
}
 
Example #20
Source File: MinSizeTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class MinSizeTargetBean {

        @MinSize(5)
        public Object value;
    }
    MinSizeTargetBean target = new MinSizeTargetBean();
    VALIDATOR.validate(target);
}
 
Example #21
Source File: IPv4Test.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class IPv4TargetBean {

        @IPv4
        public Object value;
    }
    IPv4TargetBean target = new IPv4TargetBean();
    VALIDATOR.validate(target);
}
 
Example #22
Source File: HalfwidthKatakanaTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class HalfwidthKatakanaTargetBean {

        @HalfwidthKatakana
        public Object value;
    }
    HalfwidthKatakanaTargetBean target = new HalfwidthKatakanaTargetBean();
    VALIDATOR.validate(target);
}
 
Example #23
Source File: EqualsSizeTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class EqualsSizeTargetBean {

        @EqualsSize(5)
        public Object value;
    }
    EqualsSizeTargetBean target = new EqualsSizeTargetBean();
    VALIDATOR.validate(target);
}
 
Example #24
Source File: RegexTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldThrowUnexpectedTypeException() {

    thrown.expect(UnexpectedTypeException.class);
    thrown.expectMessage(containsString("HV000030"));
    class RegexTargetBean {

        @Regex("(ok|OK)")
        public Object value;
    }
    RegexTargetBean target = new RegexTargetBean();
    VALIDATOR.validate(target);
}
 
Example #25
Source File: TransformApiDocService.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Does transformation API documentation
 *
 * @param serviceId  the unique service id
 * @param apiDocInfo the API doc and additional information about transformation
 * @return the transformed API documentation relative to Gateway
 * @throws ApiDocTransformationException if could not convert Swagger/OpenAPI to JSON
 * @throws UnexpectedTypeException       if response is not a Swagger/OpenAPI type object
 */
public String transformApiDoc(String serviceId, ApiDocInfo apiDocInfo) {
    //maybe null check of apidocinfo
    AbstractApiDocService abstractApiDocService = beanApiDocFactory.apply(apiDocInfo.getApiDocContent());
    if (abstractApiDocService == null) {
        throw new UnexpectedTypeException("Response is not a Swagger or OpenAPI type object.");
    }

    return abstractApiDocService.transformApiDoc(serviceId, apiDocInfo);
}
 
Example #26
Source File: ApiDocV3Service.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
public String transformApiDoc(String serviceId, ApiDocInfo apiDocInfo) {
    SwaggerParseResult parseResult = new OpenAPIV3Parser().readContents(apiDocInfo.getApiDocContent());
    OpenAPI openAPI = parseResult.getOpenAPI();

    if (openAPI == null) {
        log.debug("Could not convert response body to an OpenAPI object for service {}. {}", serviceId, parseResult.getMessages());

        if (parseResult.getMessages() == null) {
            throw new UnexpectedTypeException("Response is not an OpenAPI type object.");
        } else {
            throw new UnexpectedTypeException(parseResult.getMessages().toString());
        }
    }

    boolean hidden = isHidden(openAPI.getTags());

    updatePaths(openAPI, serviceId, apiDocInfo, hidden);
    updateServerAndLink(openAPI, serviceId, hidden);
    updateExternalDoc(openAPI, apiDocInfo);

    try {
        return initializeObjectMapper().writeValueAsString(openAPI);
    } catch (JsonProcessingException e) {
        log.debug("Could not convert Swagger to JSON", e);
        throw new ApiDocTransformationException("Could not convert Swagger to JSON");
    }
}
 
Example #27
Source File: ApiDocV2ServiceTest.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void givenSwaggerJsonNotAsExpectedFormat_whenConvertToSwagger_thenThrowIOException () throws IOException {
    String apiDocContent = "Failed content";

    ApiDocInfo apiDocInfo = new ApiDocInfo(null, apiDocContent, null);

    exceptionRule.expect(UnexpectedTypeException.class);
    exceptionRule.expectMessage("Response is not a Swagger type object.");

    apiDocV2Service.transformApiDoc(SERVICE_ID, apiDocInfo);
}
 
Example #28
Source File: ApiTransformationConfigTest.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testApiDocFactory_whenApDocVersionIsNotAsExpectedFormat() {
    exceptionRule.expect(UnexpectedTypeException.class);
    exceptionRule.expectMessage("Response is not a Swagger or OpenAPI type object");

    AbstractApiDocService abstractApiDocService = beanApiDocFactory.apply("FAILED FORMAT");
    assertNull(abstractApiDocService);
}
 
Example #29
Source File: ApiDocV3ServiceTest.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void givenEmptyJson_whenApiDocTransform_thenThrowException() {
    String invalidJson = "";
    ApiInfo apiInfo = new ApiInfo("org.zowe.apicatalog", "api/v1", "3.0.0", "https://localhost:10014/apicatalog/api-doc", "https://www.zowe.org");
    ApiDocInfo apiDocInfo = new ApiDocInfo(apiInfo, invalidJson, null);

    exceptionRule.expect(UnexpectedTypeException.class);
    exceptionRule.expectMessage("No swagger supplied");
    apiDocV3Service.transformApiDoc(SERVICE_ID, apiDocInfo);
}
 
Example #30
Source File: ApiDocV3ServiceTest.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void givenInvalidJson_whenApiDocTransform_thenThrowException() {
    String invalidJson = "nonsense";
    ApiInfo apiInfo = new ApiInfo("org.zowe.apicatalog", "api/v1", "3.0.0", "https://localhost:10014/apicatalog/api-doc", "https://www.zowe.org");
    ApiDocInfo apiDocInfo = new ApiDocInfo(apiInfo, invalidJson, null);

    exceptionRule.expect(UnexpectedTypeException.class);
    exceptionRule.expectMessage("attribute openapi is not of type `object`");
    apiDocV3Service.transformApiDoc(SERVICE_ID, apiDocInfo);
}