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());
}
}
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());
}
}
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));
}
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));
}
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);
}
Aggregations