Search in sources :

Example 21 with JSONConfig

use of org.wso2.carbon.apimgt.gateway.threatprotection.configuration.JSONConfig in project carbon-apimgt by wso2.

the class JsonSchemaValidatorTest method testConfigureSchemaProperties.

/**
 * Test Json configure properties method.
 */
@Test
public void testConfigureSchemaProperties() {
    log.info("Running the test case to Configure the schema properties.");
    JSONConfig testJsonConfig = new JSONConfig();
    testJsonConfig.setMaxPropertyCount(Integer.valueOf("5"));
    testJsonConfig.setMaxStringLength(Integer.valueOf("5"));
    testJsonConfig.setMaxArrayElementCount(Integer.valueOf("5"));
    testJsonConfig.setMaxKeyLength(Integer.valueOf("5"));
    testJsonConfig.setMaxJsonDepth(Integer.valueOf("5"));
    Mockito.when(messageContext.getProperty(ThreatProtectorConstants.MAX_PROPERTY_COUNT)).thenReturn("5");
    Mockito.when(messageContext.getProperty(ThreatProtectorConstants.MAX_STRING_LENGTH)).thenReturn("5");
    Mockito.when(messageContext.getProperty(ThreatProtectorConstants.MAX_ARRAY_ELEMENT_COUNT)).thenReturn("5");
    Mockito.when(messageContext.getProperty(ThreatProtectorConstants.MAX_KEY_LENGTH)).thenReturn("5");
    Mockito.when(messageContext.getProperty(ThreatProtectorConstants.MAX_JSON_DEPTH)).thenReturn("5");
    JsonSchemaValidator jsonSchemaValidator = new JsonSchemaValidator();
    JSONConfig jsonConfig = jsonSchemaValidator.configureSchemaProperties(messageContext);
    assertEquals(jsonConfig.getMaxPropertyCount(), testJsonConfig.getMaxPropertyCount());
    assertEquals(jsonConfig.getMaxStringLength(), testJsonConfig.getMaxStringLength());
    assertEquals(jsonConfig.getMaxArrayElementCount(), testJsonConfig.getMaxArrayElementCount());
    assertEquals(jsonConfig.getMaxKeyLength(), testJsonConfig.getMaxKeyLength());
    assertEquals(jsonConfig.getMaxJsonDepth(), testJsonConfig.getMaxJsonDepth());
    log.info("Successfully completed testConfigureSchemaProperties test case.");
}
Also used : JSONConfig(org.wso2.carbon.apimgt.gateway.threatprotection.configuration.JSONConfig) Test(org.junit.Test)

Aggregations

JSONConfig (org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.JSONConfig)15 Test (org.testng.annotations.Test)13 JSONAnalyzer (org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer)12 JSONConfig (org.wso2.carbon.apimgt.gateway.threatprotection.configuration.JSONConfig)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Gson (com.google.gson.Gson)2 JsonObject (com.google.gson.JsonObject)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 APIMThreatAnalyzer (org.wso2.carbon.apimgt.gateway.threatprotection.analyzer.APIMThreatAnalyzer)2 Environment (org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment)2 BufferedInputStream (java.io.BufferedInputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 BBoolean (org.ballerinalang.model.values.BBoolean)1