Search in sources :

Example 1 with MockUp

use of mockit.MockUp in project java-chassis by ServiceComb.

the class SSLManagerTest method testCreateSSLContextKeyManagementException.

@Test
public void testCreateSSLContextKeyManagementException() {
    SSLOption option = SSLOption.build(DIR + "/server.ssl.properties");
    SSLCustom custom = new SSLCustom() {

        @Override
        public String getFullPath(String filename) {
            return DIR + "/ssl/" + filename;
        }

        @Override
        public char[] decode(char[] encrypted) {
            return encrypted;
        }
    };
    new MockUp<SSLContext>() {

        @Mock
        public final SSLContext getInstance(String type) throws KeyManagementException {
            throw new KeyManagementException();
        }
    };
    try {
        SSLContext context = SSLManager.createSSLContext(option, custom);
        Assert.assertNotNull(context);
    } catch (Exception e) {
        Assert.assertEquals("java.lang.IllegalArgumentException", e.getClass().getName());
    }
}
Also used : MockUp(mockit.MockUp) SSLContext(javax.net.ssl.SSLContext) KeyManagementException(java.security.KeyManagementException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) UnknownHostException(java.net.UnknownHostException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Test(org.junit.Test)

Example 2 with MockUp

use of mockit.MockUp in project java-chassis by ServiceComb.

the class SSLManagerTest method testCreateSSLServerSocketIOException.

@Test
public void testCreateSSLServerSocketIOException() {
    SSLOption option = SSLOption.build(DIR + "/server.ssl.properties");
    SSLCustom custom = new SSLCustom() {

        @Override
        public String getFullPath(String filename) {
            return DIR + "/ssl/" + filename;
        }

        @Override
        public char[] decode(char[] encrypted) {
            return encrypted;
        }
    };
    new MockUp<SSLContext>() {

        @Mock
        public final SSLContext getInstance(String type) throws IOException {
            throw new IOException();
        }
    };
    try {
        SSLServerSocket context = SSLManager.createSSLServerSocket(option, custom);
        Assert.assertNotNull(context);
    } catch (Exception e) {
        Assert.assertEquals("java.lang.IllegalArgumentException", e.getClass().getName());
    }
}
Also used : MockUp(mockit.MockUp) IOException(java.io.IOException) SSLServerSocket(javax.net.ssl.SSLServerSocket) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) UnknownHostException(java.net.UnknownHostException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Test(org.junit.Test)

Example 3 with MockUp

use of mockit.MockUp in project java-chassis by ServiceComb.

the class TestFortifyUtils method testReadAttributes.

@Test
public void testReadAttributes() {
    Path file = new File("src/test/resources/config/test.1.properties").toPath();
    new MockUp<FortifyUtils>() {

        @SuppressWarnings("unused")
        public boolean isInSecureDir(Path file) {
            return true;
        }
    };
    try {
        Files.readAttributes(file, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        Assert.assertTrue(false);
    }
    FortifyUtils.isInSecureResult(file);
    Assert.assertNotEquals(false, FortifyUtils.isInSecureResult(file));
}
Also used : Path(java.nio.file.Path) MockUp(mockit.MockUp) IOException(java.io.IOException) File(java.io.File) Test(org.junit.Test)

Example 4 with MockUp

use of mockit.MockUp in project java-chassis by ServiceComb.

the class TestFortifyUtils method testIsInSecureResult.

@Test
public void testIsInSecureResult() {
    Path file = new File("src/test/resources/config/test.1.properties").toPath();
    new MockUp<FortifyUtils>() {

        @SuppressWarnings("unused")
        public boolean isInSecureDir(Path file, UserPrincipal user, int symlinkDepth) {
            return false;
        }
    };
    FortifyUtils.isInSecureResult(file);
    Assert.assertNotEquals(false, FortifyUtils.isInSecureResult(file));
}
Also used : Path(java.nio.file.Path) MockUp(mockit.MockUp) File(java.io.File) UserPrincipal(java.nio.file.attribute.UserPrincipal) Test(org.junit.Test)

Example 5 with MockUp

use of mockit.MockUp in project java-chassis by ServiceComb.

the class TestHighwayCodec method testReadRequestHeader.

@Test
public void testReadRequestHeader() {
    boolean status = true;
    try {
        new MockUp<NotWrapSchema>() {

            @Mock
            public Object readObject(Input input) throws IOException {
                return new RequestHeader();
            }
        };
        bodyBuffer = Buffer.buffer("\"abc\"");
        RequestHeader requestHeader = HighwayCodec.readRequestHeader(bodyBuffer);
        Assert.assertNotNull(requestHeader);
        Assert.assertEquals(0, requestHeader.getFlags());
    } catch (Exception e) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : Input(io.protostuff.Input) RequestHeader(io.servicecomb.transport.highway.message.RequestHeader) MockUp(mockit.MockUp) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

MockUp (mockit.MockUp)391 Test (org.junit.Test)349 RowImpl (org.apache.carbondata.core.scan.filter.intf.RowImpl)80 ExpressionResult (org.apache.carbondata.core.scan.expression.ExpressionResult)78 ColumnExpression (org.apache.carbondata.core.scan.expression.ColumnExpression)77 Expectations (mockit.Expectations)56 ArrayList (java.util.ArrayList)51 IOException (java.io.IOException)30 HashMap (java.util.HashMap)30 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)29 Handler (io.vertx.core.Handler)27 Buffer (io.vertx.core.buffer.Buffer)26 Mock (mockit.Mock)22 Invocation (org.apache.servicecomb.core.Invocation)22 Holder (javax.xml.ws.Holder)21 Encoding (org.apache.carbondata.core.metadata.encoder.Encoding)21 Map (java.util.Map)20 Before (org.junit.Before)20 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)16 HttpClientOptions (io.vertx.core.http.HttpClientOptions)15