http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/test/com/cloud/utils/crypto/EncryptionSecretKeyCheckerTest.java ---------------------------------------------------------------------- diff --git a/utils/test/com/cloud/utils/crypto/EncryptionSecretKeyCheckerTest.java b/utils/test/com/cloud/utils/crypto/EncryptionSecretKeyCheckerTest.java deleted file mode 100644 index 0f3f058..0000000 --- a/utils/test/com/cloud/utils/crypto/EncryptionSecretKeyCheckerTest.java +++ /dev/null @@ -1,45 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils.crypto; - -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.Properties; - -import org.junit.Assert; -import org.junit.Test; - -import com.cloud.utils.crypt.EncryptionSecretKeyChecker; -import com.cloud.utils.db.DbProperties; -import com.cloud.utils.exception.CloudRuntimeException; - -public class EncryptionSecretKeyCheckerTest { - - private EncryptionSecretKeyChecker checker = new EncryptionSecretKeyChecker(); - - @Test(expected = CloudRuntimeException.class) - public void testKeyFileDoesNotExists() throws IOException, URISyntaxException { - Assert.assertNotNull(checker); - Properties properties = DbProperties.getDbProperties(); - properties.setProperty("db.cloud.encryption.type", "file"); - checker.check(properties); - } - -} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/test/com/cloud/utils/crypto/RSAHelperTest.java ---------------------------------------------------------------------- diff --git a/utils/test/com/cloud/utils/crypto/RSAHelperTest.java b/utils/test/com/cloud/utils/crypto/RSAHelperTest.java deleted file mode 100644 index 27d9d50..0000000 --- a/utils/test/com/cloud/utils/crypto/RSAHelperTest.java +++ /dev/null @@ -1,54 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils.crypto; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import org.junit.Test; - -import com.cloud.utils.crypt.RSAHelper; - -public class RSAHelperTest { - @Test - public void testEncryptWithRSA() { - String rsaKey = - "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC2D2Cs0XAEqm+ajJpumIPrMpKp0CWtIW+8ZY2/MJCW" - + "hge1eY18u9I3PPnkMVJsTOaN0wQojjw4AkKgKjNZXA9wyUq56UyN/stmipu8zifWPgxQGDRkuzzZ6buk" - + "ef8q2Awjpo8hv5/0SRPJxQLEafESnUP+Uu/LUwk5VVC7PHzywJRUGFuzDl/uT72+6hqpL2YpC6aTl4/P" - + "2eDvUQhCdL9dBmUSFX8ftT53W1jhsaQl7mPElVgSCtWz3IyRkogobMPrpJW/IPKEiojKIuvNoNv4CDR6" + "ybeVjHOJMb9wi62rXo+CzUsW0Y4jPOX/OykAm5vrNOhQhw0aaBcv5XVv8BRX"; - String encryptedString = RSAHelper.encryptWithSSHPublicKey(rsaKey, "content"); - assertNotNull(encryptedString); - } - - @Test - public void testEncryptWithDSA() { - String dssKey = - "ssh-dss AAAAB3NzaC1kc3MAAACBALbaewDnzZ5AcGbZno7VW1m7Si3Q+yEANXZioVupfSwOP0q9aP2iV" - + "tyqq575JnUVZXMDR2Gr254F/qCJ0TKAvucN0gcd2XslX4jBcu1Z7s7YZf6d7fC58k0NE6/keokJNKhQO" - + "i56iirRzSA/YFrD64mzfq6rEmai0q7GjGGP0RT1AAAAFQDO5++6JonyqnoRkV9Yl1OaEOPjVwAAAIAYA" - + "tqtKtU/INlTIuL3wt3nyKzwPUnz3fqxP5Ger3OlRZsOahalTFt2OF5jGGmCunyBTRteOetZObr0QhUIF" - + "4bSDr6UiYYYbH1ES0ws/t1mDIeTh3UUHV1QYACN6c07FKyKLMtB9AthiG2FMLKCEedG3NeXItuNzsuQD" - + "+n/K1rzMAAAAIBi5SM4pFPiB7BvTZvARV56vrG5QNgWVazSwbwgl/EACiWYbRauHDUQA9f+Rq+ayWcsR" - + "os1CD+Q81y9SmlQaZVKkSPZLxXfu5bi3s4o431xjilhZdt4vKbj2pK364IjghJPNBBfmRXzlj9awKxr/" + "UebZcBgNRyeky7VZSbbF2jQSQ=="; - String encryptedString = RSAHelper.encryptWithSSHPublicKey(dssKey, "content"); - assertNull(encryptedString); - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/test/com/cloud/utils/encoding/UrlEncoderTest.java ---------------------------------------------------------------------- diff --git a/utils/test/com/cloud/utils/encoding/UrlEncoderTest.java b/utils/test/com/cloud/utils/encoding/UrlEncoderTest.java deleted file mode 100644 index 3d4dfc9..0000000 --- a/utils/test/com/cloud/utils/encoding/UrlEncoderTest.java +++ /dev/null @@ -1,33 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils.encoding; - -import org.junit.Assert; -import org.junit.Test; - -public class UrlEncoderTest { - @Test - public void encode() { - Assert.assertEquals("%2Ftmp%2F", new URLEncoder().encode("/tmp/")); - Assert.assertEquals("%20", new URLEncoder().encode(" ")); - Assert.assertEquals("%5F", new URLEncoder().encode("_")); - Assert.assertEquals("%25", new URLEncoder().encode("%")); - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/test/com/cloud/utils/exception/ExceptionUtilTest.java ---------------------------------------------------------------------- diff --git a/utils/test/com/cloud/utils/exception/ExceptionUtilTest.java b/utils/test/com/cloud/utils/exception/ExceptionUtilTest.java deleted file mode 100644 index 9e1948e..0000000 --- a/utils/test/com/cloud/utils/exception/ExceptionUtilTest.java +++ /dev/null @@ -1,52 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils.exception; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.FileNotFoundException; -import java.io.IOException; - -import org.junit.Test; - -public class ExceptionUtilTest { - - @Test - public void test() throws Exception { - FileNotFoundException fnfe = new FileNotFoundException(); - try { - ExceptionUtil.rethrow(fnfe, IOException.class); - fail(); - } catch (IOException e) { - assertTrue("we won !?!", true); - } - - ExceptionUtil.rethrow(fnfe, ClassNotFoundException.class); - - try { - ExceptionUtil.rethrow(fnfe, FileNotFoundException.class); - fail(); - } catch (FileNotFoundException e) { - assertTrue("we won !?!", true); - } - } - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/test/com/cloud/utils/net/Ip4AddressTest.java ---------------------------------------------------------------------- diff --git a/utils/test/com/cloud/utils/net/Ip4AddressTest.java b/utils/test/com/cloud/utils/net/Ip4AddressTest.java deleted file mode 100644 index 79ff238..0000000 --- a/utils/test/com/cloud/utils/net/Ip4AddressTest.java +++ /dev/null @@ -1,40 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.utils.net; - -import org.junit.Assert; -import org.junit.Test; - -import com.google.common.testing.EqualsTester; - -public class Ip4AddressTest { - - @Test - public void testEquals() throws Exception { - new EqualsTester() - .addEqualityGroup(new Ip4Address("0.0.0.1", "00:00:00:00:00:02"), new Ip4Address(1L, 2L)) - .addEqualityGroup(new Ip4Address("0.0.0.1", "00:00:00:00:00:00"), new Ip4Address(1L, 0L), new Ip4Address(1L, 0L), new Ip4Address(1L), new Ip4Address("0.0.0.1")) - .testEquals(); - } - - @Test - public void testIsSameAddressAs() { - Assert.assertTrue("1 and one should be considdered the same address", new Ip4Address(1L, 5L).isSameAddressAs("0.0.0.1")); - Assert.assertFalse("zero and 0L should be considdered the same address but a Long won't be accepted", new Ip4Address("0.0.0.0", "00:00:00:00:00:08").isSameAddressAs(0L)); - } - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/test/com/cloud/utils/net/IpTest.java ---------------------------------------------------------------------- diff --git a/utils/test/com/cloud/utils/net/IpTest.java b/utils/test/com/cloud/utils/net/IpTest.java deleted file mode 100644 index 89608f1..0000000 --- a/utils/test/com/cloud/utils/net/IpTest.java +++ /dev/null @@ -1,63 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils.net; - -import static org.junit.Assert.assertEquals; - -import org.junit.Assert; -import org.junit.Test; - -import com.google.common.testing.EqualsTester; - -public class IpTest { - - @Test - public void testUltimate() { - Ip max = new Ip(2L * Integer.MAX_VALUE +1 ); - assertEquals("Maximal address not created", "255.255.255.255", max.addr()); - } - @Test - public void testTurningOfTheCentury() { - Ip eve = new Ip(Integer.MAX_VALUE); - assertEquals("Minimal address not created", "127.255.255.255", eve.addr()); - Ip dawn = new Ip(Integer.MAX_VALUE + 1L); - assertEquals("Minimal address not created", "128.0.0.0", dawn.addr()); - } - @Test - public void testStart() { - Ip min = new Ip(0); - assertEquals("Minimal address not created", "0.0.0.0", min.addr()); - } - - @Test - public void testEquals() { - new EqualsTester() - .addEqualityGroup(new Ip("0.0.0.1"), new Ip(1L)) - .addEqualityGroup(new Ip("0.0.0.0"), new Ip(0L)) - .testEquals(); - } - - @Test - public void testIsSameAddressAs() { - Assert.assertTrue("1 and one should be considdered the same address", new Ip(1L).isSameAddressAs("0.0.0.1")); - Assert.assertTrue("zero and 0L should be considdered the same address", new Ip("0.0.0.0").isSameAddressAs(0L)); - } - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/test/com/cloud/utils/net/MacAddressTest.java ---------------------------------------------------------------------- diff --git a/utils/test/com/cloud/utils/net/MacAddressTest.java b/utils/test/com/cloud/utils/net/MacAddressTest.java deleted file mode 100644 index 845a435..0000000 --- a/utils/test/com/cloud/utils/net/MacAddressTest.java +++ /dev/null @@ -1,60 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils.net; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class MacAddressTest { - - @Test - public final void testMacAddress() throws Exception { - MacAddress mac = new MacAddress(); - assertEquals(0L,mac.toLong()); - } - - @Test - public final void testMacAddressLong() throws Exception { - MacAddress mac = new MacAddress(1L); - assertEquals(1L,mac.toLong()); - } - - @Test - public final void testMacAddressToLong() throws Exception { - // TODO this test should fail this address is beyond the acceptable range for macaddresses - MacAddress mac = new MacAddress(Long.MAX_VALUE); - assertEquals(Long.MAX_VALUE,mac.toLong()); - System.out.println(mac.toString()); - } - - // TODO public final void testToLong() throws Exception { - // TODO public final void testToByteArray() throws Exception { - // TODO public final void testToStringString() throws Exception { - // TODO public final void testToString() throws Exception { - // TODO public final void testGetMacAddress() throws Exception { - // TODO public final void testParse() throws Exception { - // TODO public final void testMain() throws Exception { - // TODO public final void testParseLong() throws Exception { - // TODO public final void testParseInt() throws Exception { - // TODO public final void testParseShort() throws Exception { - // TODO public final void testParseByte() throws Exception { - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/test/com/cloud/utils/net/NetUtilsTest.java ---------------------------------------------------------------------- diff --git a/utils/test/com/cloud/utils/net/NetUtilsTest.java b/utils/test/com/cloud/utils/net/NetUtilsTest.java deleted file mode 100644 index 1ab4459..0000000 --- a/utils/test/com/cloud/utils/net/NetUtilsTest.java +++ /dev/null @@ -1,421 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils.net; - -import static org.hamcrest.Matchers.anyOf; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.lessThanOrEqualTo; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -import java.math.BigInteger; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.apache.log4j.Logger; -import org.junit.Test; - -import com.googlecode.ipv6.IPv6Address; - -public class NetUtilsTest { - - private static final Logger s_logger = Logger.getLogger(NetUtilsTest.class); - - @Test - public void testGetRandomIpFromCidrWithSize24() throws Exception { - final String cidr = "192.168.124.1"; - final int size = 24; - final int netCharacters = 12; - - final long ip = NetUtils.getRandomIpFromCidr(cidr, size, new TreeSet<Long>()); - - assertThat("The ip " + NetUtils.long2Ip(ip) + " retrieved must be within the cidr " + cidr + "/" + size, cidr.substring(0, netCharacters), equalTo(NetUtils.long2Ip(ip) - .substring(0, netCharacters))); - } - - @Test - public void testGetRandomIpFromCidrWithSize16() throws Exception { - final String cidr = "192.168.124.1"; - final int size = 16; - final int netCharacters = 8; - - final long ip = NetUtils.getRandomIpFromCidr(cidr, 16, new TreeSet<Long>()); - - assertThat("The ip " + NetUtils.long2Ip(ip) + " retrieved must be within the cidr " + cidr + "/" + size, cidr.substring(0, netCharacters), equalTo(NetUtils.long2Ip(ip) - .substring(0, netCharacters))); - } - - @Test - public void testGetRandomIpFromCidrWithSize8() throws Exception { - final String cidr = "192.168.124.1"; - final int size = 8; - final int netCharacters = 4; - - final long ip = NetUtils.getRandomIpFromCidr(cidr, 16, new TreeSet<Long>()); - - assertThat("The ip " + NetUtils.long2Ip(ip) + " retrieved must be within the cidr " + cidr + "/" + size, cidr.substring(0, netCharacters), equalTo(NetUtils.long2Ip(ip) - .substring(0, netCharacters))); - } - - @Test - public void testGetRandomIpFromCidrUsignAvoid() throws Exception { - final String cidr = "192.168.124.1"; - final int size = 30; - - final SortedSet<Long> avoid = new TreeSet<Long>(); - long ip = NetUtils.getRandomIpFromCidr(cidr, size, avoid); - assertThat("We should be able to retrieve an ip on the first call.", ip, not(equalTo(-1L))); - avoid.add(ip); - ip = NetUtils.getRandomIpFromCidr(cidr, size, avoid); - assertThat("We should be able to retrieve an ip on the second call.", ip, not(equalTo(-1L))); - assertThat("ip returned is not in the avoid list", avoid, not(contains(ip))); - avoid.add(ip); - ip = NetUtils.getRandomIpFromCidr(cidr, size, avoid); - assertThat("We should be able to retrieve an ip on the third call.", ip, not(equalTo(-1L))); - assertThat("ip returned is not in the avoid list", avoid, not(contains(ip))); - avoid.add(ip); - ip = NetUtils.getRandomIpFromCidr(cidr, size, avoid); - assertEquals("This should be -1 because we ran out of ip addresses: " + ip, ip, -1); - } - - @Test - public void testIsValidS2SVpnPolicy() { - assertTrue(NetUtils.isValidS2SVpnPolicy("aes128-sha1")); - assertTrue(NetUtils.isValidS2SVpnPolicy("3des-sha1")); - assertTrue(NetUtils.isValidS2SVpnPolicy("3des-sha1,aes256-sha1")); - assertTrue(NetUtils.isValidS2SVpnPolicy("3des-md5;modp1024")); - assertTrue(NetUtils.isValidS2SVpnPolicy("3des-sha1,aes128-sha1;modp1536")); - assertFalse(NetUtils.isValidS2SVpnPolicy("des-md5;modp1024,aes128-sha1;modp1536")); - assertFalse(NetUtils.isValidS2SVpnPolicy("des-sha1")); - assertFalse(NetUtils.isValidS2SVpnPolicy("abc-123,ase-sha1")); - assertFalse(NetUtils.isValidS2SVpnPolicy("de-sh,aes-sha1")); - assertFalse(NetUtils.isValidS2SVpnPolicy("")); - assertFalse(NetUtils.isValidS2SVpnPolicy(";modp1536")); - assertFalse(NetUtils.isValidS2SVpnPolicy(",aes;modp1536,,,")); - } - - @Test - public void testGetIp6FromRange() { - assertEquals(NetUtils.getIp6FromRange("1234:5678::1-1234:5678::1"), "1234:5678::1"); - for (int i = 0; i < 5; i++) { - final String ip = NetUtils.getIp6FromRange("1234:5678::1-1234:5678::2"); - assertThat(ip, anyOf(equalTo("1234:5678::1"), equalTo("1234:5678::2"))); - s_logger.info("IP is " + ip); - } - String ipString = null; - final IPv6Address ipStart = IPv6Address.fromString("1234:5678::1"); - final IPv6Address ipEnd = IPv6Address.fromString("1234:5678::ffff:ffff:ffff:ffff"); - for (int i = 0; i < 10; i++) { - ipString = NetUtils.getIp6FromRange(ipStart.toString() + "-" + ipEnd.toString()); - s_logger.info("IP is " + ipString); - final IPv6Address ip = IPv6Address.fromString(ipString); - assertThat(ip, greaterThanOrEqualTo(ipStart)); - assertThat(ip, lessThanOrEqualTo(ipEnd)); - } - } - - @Test - public void testCountIp6InRange() { - assertEquals(new BigInteger("2"), NetUtils.countIp6InRange("1234:5678::1-1234:5678::2")); - } - - @Test - public void testCountIp6InRangeWithInvalidRange() { - assertEquals(null, NetUtils.countIp6InRange("1234:5678::2-1234:5678::0")); - } - - @Test - public void testCountIp6InRangeWithNullStart() { - assertEquals(null, NetUtils.countIp6InRange("-1234:5678::0")); - } - - @Test - public void testCountIp6InRangeWithNoEnd() { - assertEquals(new BigInteger("1"), NetUtils.countIp6InRange("1234:5678::2")); - } - - @Test - public void testGetIp6CidrSize() { - assertEquals(NetUtils.getIp6CidrSize("1234:5678::1/32"), 32); - assertEquals(NetUtils.getIp6CidrSize("1234:5678::1"), 0); - } - - @Test - public void testIsValidIp6Cidr() { - assertTrue(NetUtils.isValidIp6Cidr("1234:5678::1/64")); - assertFalse(NetUtils.isValidIp6Cidr("1234:5678::1")); - } - - @Test - public void testIsValidIpv6() { - assertTrue(NetUtils.isValidIpv6("fc00::1")); - assertFalse(NetUtils.isValidIpv6("")); - assertFalse(NetUtils.isValidIpv6(null)); - assertFalse(NetUtils.isValidIpv6("1234:5678::1/64")); - } - - @Test - public void testIsIp6InRange() { - assertTrue(NetUtils.isIp6InRange("1234:5678:abcd::1", "1234:5678:abcd::1-1234:5678:abcd::1")); - assertFalse(NetUtils.isIp6InRange("1234:5678:abcd::1", "1234:5678:abcd::2-1234:5678:abcd::1")); - assertFalse(NetUtils.isIp6InRange("1234:5678:abcd::1", null)); - assertTrue(NetUtils.isIp6InRange("1234:5678:abcd::1", "1234:5678::1-1234:5679::1")); - } - - @Test - public void testIsIp6InNetwork() { - assertFalse(NetUtils.isIp6InNetwork("1234:5678:abcd::1", "1234:5678::/64")); - assertTrue(NetUtils.isIp6InNetwork("1234:5678::1", "1234:5678::/64")); - assertTrue(NetUtils.isIp6InNetwork("1234:5678::ffff:ffff:ffff:ffff", "1234:5678::/64")); - assertTrue(NetUtils.isIp6InNetwork("1234:5678::", "1234:5678::/64")); - } - - @Test - public void testGetNextIp6InRange() { - String range = "1234:5678::1-1234:5678::8000:0000"; - assertEquals(NetUtils.getNextIp6InRange("1234:5678::8000:0", range), "1234:5678::1"); - assertEquals(NetUtils.getNextIp6InRange("1234:5678::7fff:ffff", range), "1234:5678::8000:0"); - assertEquals(NetUtils.getNextIp6InRange("1234:5678::1", range), "1234:5678::2"); - range = "1234:5678::1-1234:5678::ffff:ffff:ffff:ffff"; - assertEquals(NetUtils.getNextIp6InRange("1234:5678::ffff:ffff:ffff:ffff", range), "1234:5678::1"); - } - - @Test - public void testIsIp6RangeOverlap() { - assertFalse(NetUtils.isIp6RangeOverlap("1234:5678::1-1234:5678::ffff", "1234:5678:1::1-1234:5678:1::ffff")); - assertTrue(NetUtils.isIp6RangeOverlap("1234:5678::1-1234:5678::ffff", "1234:5678::2-1234:5678::f")); - assertTrue(NetUtils.isIp6RangeOverlap("1234:5678::f-1234:5678::ffff", "1234:5678::2-1234:5678::f")); - assertFalse(NetUtils.isIp6RangeOverlap("1234:5678::f-1234:5678::ffff", "1234:5678::2-1234:5678::e")); - assertFalse(NetUtils.isIp6RangeOverlap("1234:5678::f-1234:5678::f", "1234:5678::2-1234:5678::e")); - } - - @Test - public void testStandardizeIp6Address() { - assertEquals(NetUtils.standardizeIp6Address("1234:0000:0000:5678:0000:0000:ABCD:0001"), "1234::5678:0:0:abcd:1"); - assertEquals(NetUtils.standardizeIp6Cidr("1234:0000:0000:5678:0000:0000:ABCD:0001/64"), "1234:0:0:5678::/64"); - } - - @Test - public void testGenerateUriForPvlan() { - assertEquals("pvlan://123-i456", NetUtils.generateUriForPvlan("123", "456").toString()); - } - - @Test - public void testGetPrimaryPvlanFromUri() { - assertEquals("123", NetUtils.getPrimaryPvlanFromUri(NetUtils.generateUriForPvlan("123", "456"))); - } - - @Test - public void testGetIsolatedPvlanFromUri() { - assertEquals("456", NetUtils.getIsolatedPvlanFromUri(NetUtils.generateUriForPvlan("123", "456"))); - } - - @Test - public void testIsValidCIDR() throws Exception { - //Test to check IP Range of 2 CIDR - final String cidrFirst = "10.0.144.0/20"; - final String cidrSecond = "10.0.151.0/20"; - final String cidrThird = "10.0.144.0/21"; - - assertTrue(NetUtils.isValidCIDR(cidrFirst)); - assertTrue(NetUtils.isValidCIDR(cidrSecond)); - assertTrue(NetUtils.isValidCIDR(cidrThird)); - } - - @Test - public void testIsValidCidrList() throws Exception { - final String cidrFirst = "10.0.144.0/20,1.2.3.4/32,5.6.7.8/24"; - final String cidrSecond = "10.0.151.0/20,129.0.0.0/4"; - final String cidrThird = "10.0.144.0/21"; - - assertTrue(NetUtils.isValidCidrList(cidrFirst)); - assertTrue(NetUtils.isValidCidrList(cidrSecond)); - assertTrue(NetUtils.isValidCidrList(cidrThird)); - } - - @Test - public void testIsSameIpRange() { - final String cidrFirst = "10.0.144.0/20"; - final String cidrSecond = "10.0.151.0/20"; - final String cidrThird = "10.0.144.0/21"; - - //Check for exactly same CIDRs - assertTrue(NetUtils.isSameIpRange(cidrFirst, cidrFirst)); - //Check for 2 different CIDRs, but same IP Range - assertTrue(NetUtils.isSameIpRange(cidrFirst, cidrSecond)); - //Check for 2 different CIDRs and different IP Range - assertFalse(NetUtils.isSameIpRange(cidrFirst, cidrThird)); - //Check for Incorrect format of CIDR - assertFalse(NetUtils.isSameIpRange(cidrFirst, "10.3.6.5/50")); - } - - @Test - public void testGenerateMacOnIncrease() { - String mac = "06:01:23:00:45:67"; - assertEquals("06:01:25:00:45:67", NetUtils.generateMacOnIncrease(mac, 2)); - assertEquals("06:01:33:00:45:67", NetUtils.generateMacOnIncrease(mac, 16)); - mac = "06:ff:ff:00:45:67"; - assertEquals("06:00:00:00:45:67", NetUtils.generateMacOnIncrease(mac, 1)); - assertEquals("06:00:0f:00:45:67", NetUtils.generateMacOnIncrease(mac, 16)); - } - - @Test - public void testGetLocalIPString() { - assertNotNull(NetUtils.getLocalIPString()); - } - - @Test - public void testSameIsolationId() { - assertTrue(NetUtils.isSameIsolationId("1", "vlan://1")); - assertTrue(NetUtils.isSameIsolationId("", null)); - assertTrue(NetUtils.isSameIsolationId("UnTagged", "vlan://uNtAGGED")); - assertFalse(NetUtils.isSameIsolationId("2", "vlan://uNtAGGED")); - assertFalse(NetUtils.isSameIsolationId("2", "vlan://3")); - assertFalse(NetUtils.isSameIsolationId("bla", null)); - } - - @Test - public void testValidateGuestCidr() throws Exception { - final String guestCidr = "192.168.1.0/24"; - - assertTrue(NetUtils.validateGuestCidr(guestCidr)); - } - - @Test - public void testMac2Long() { - assertEquals(0l, NetUtils.mac2Long("00:00:00:00:00:00")); - assertEquals(1l, NetUtils.mac2Long("00:00:00:00:00:01")); - assertEquals(0xFFl, NetUtils.mac2Long("00:00:00:00:00:FF")); - assertEquals(0xFFAAl, NetUtils.mac2Long("00:00:00:00:FF:AA")); - assertEquals(0x11FFAAl, NetUtils.mac2Long("00:00:00:11:FF:AA")); - assertEquals(0x12345678l, NetUtils.mac2Long("00:00:12:34:56:78")); - assertEquals(0x123456789Al, NetUtils.mac2Long("00:12:34:56:78:9A")); - assertEquals(0x123456789ABCl, NetUtils.mac2Long("12:34:56:78:9A:BC")); - } - - @Test - public void testLong2Mac() { - assertEquals("00:00:00:00:00:00", NetUtils.long2Mac(0l)); - assertEquals("00:00:00:00:00:01", NetUtils.long2Mac(1l)); - assertEquals("00:00:00:00:00:ff", NetUtils.long2Mac(0xFFl)); - assertEquals("00:00:00:00:ff:aa", NetUtils.long2Mac(0xFFAAl)); - assertEquals("00:00:00:11:ff:aa", NetUtils.long2Mac(0x11FFAAl)); - assertEquals("00:00:12:34:56:78", NetUtils.long2Mac(0x12345678l)); - assertEquals("00:12:34:56:78:9a", NetUtils.long2Mac(0x123456789Al)); - assertEquals("12:34:56:78:9a:bc", NetUtils.long2Mac(0x123456789ABCl)); - } - - @Test - public void testIp2Long() { - assertEquals(0x7f000001l, NetUtils.ip2Long("127.0.0.1")); - assertEquals(0xc0a80001l, NetUtils.ip2Long("192.168.0.1")); - assertEquals(0x08080808l, NetUtils.ip2Long("8.8.8.8")); - } - - @Test - public void testLong2Ip() { - assertEquals("127.0.0.1", NetUtils.long2Ip(0x7f000001l)); - assertEquals("192.168.0.1", NetUtils.long2Ip(0xc0a80001l)); - assertEquals("8.8.8.8", NetUtils.long2Ip(0x08080808l)); - } - - @Test - public void test31BitPrefixStart() { - final String ipAddress = "192.168.0.0"; - final String cidr = "192.168.0.0/31"; - - final boolean isInRange = NetUtils.isIpWithtInCidrRange(ipAddress, cidr); - - assertTrue("Check if the subnetUtils.setInclusiveHostCount(true) has been called.", isInRange); - } - - @Test - public void test31BitPrefixEnd() { - final String ipAddress = "192.168.0.1"; - final String cidr = "192.168.0.0/31"; - - final boolean isInRange = NetUtils.isIpWithtInCidrRange(ipAddress, cidr); - - assertTrue("Check if the subnetUtils.setInclusiveHostCount(true) has been called.", isInRange); - } - - @Test - public void test31BitPrefixFail() { - final String ipAddress = "192.168.0.2"; - final String cidr = "192.168.0.0/31"; - - final boolean isInRange = NetUtils.isIpWithtInCidrRange(ipAddress, cidr); - - assertFalse("Out of the range. Why did it return true?", isInRange); - } - - @Test - public void test31BitPrefixIpRangesOverlapd() { - final String gw = "192.168.0.0"; - String ip1; - String ip2; - - for (int i = 1, j = 2; i <= 254; i++, j++) { - ip1 = "192.168.0." + i; - ip2 = "192.168.0." + j; - - final boolean doesOverlap = NetUtils.ipRangesOverlap(ip1, ip2, gw, gw); - assertFalse("It should overlap, but it's a 31-bit ip", doesOverlap); - } - } - - @Test - public void test31BitPrefixIpRangesOverlapdFail() { - String gw; - String ip1; - String ip2; - - for (int i = 10, j = 12; i <= 254; i++, j++) { - gw = "192.168.0." + i; - ip1 = "192.168.0." + i; - ip2 = "192.168.0." + j; - - final boolean doesOverlap = NetUtils.ipRangesOverlap(ip1, ip2, gw, gw); - assertTrue("It overlaps!", doesOverlap); - } - } - - @Test - public void testIs31PrefixCidrFail() { - final String cidr = "10.10.0.0/32"; - final boolean is31PrefixCidr = NetUtils.is31PrefixCidr(cidr); - - assertFalse("It should fail! 32 bit prefix.", is31PrefixCidr); - } - - @Test - public void testIs31PrefixCidr() { - final String cidr = "10.10.0.0/31"; - final boolean is31PrefixCidr = NetUtils.is31PrefixCidr(cidr); - - assertTrue("It should pass! 31 bit prefix.", is31PrefixCidr); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/test/com/cloud/utils/rest/RESTServiceConnectorTest.java ---------------------------------------------------------------------- diff --git a/utils/test/com/cloud/utils/rest/RESTServiceConnectorTest.java b/utils/test/com/cloud/utils/rest/RESTServiceConnectorTest.java deleted file mode 100644 index 6d58b5b..0000000 --- a/utils/test/com/cloud/utils/rest/RESTServiceConnectorTest.java +++ /dev/null @@ -1,395 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils.rest; - -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.util.Collections; - -import org.apache.commons.httpclient.Header; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpException; -import org.apache.commons.httpclient.HttpMethod; -import org.apache.commons.httpclient.methods.DeleteMethod; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.methods.PutMethod; -import org.apache.commons.httpclient.params.HttpClientParams; -import org.apache.http.HttpStatus; -import org.junit.Before; -import org.junit.Test; - -public class RESTServiceConnectorTest { - protected static final String UUID = "aaaa"; - protected static final String UUID_JSON_RESPONSE = "{\"uuid\" : \"aaaa\"}"; - - RESTServiceConnector connector; - HttpClient client = mock(HttpClient.class); - HttpMethod method; - String type; - String uri; - - @Before - public void setUp() { - final HttpClientParams hmp = mock(HttpClientParams.class); - when(client.getParams()).thenReturn(hmp); - connector = new RESTServiceConnector(null) { - @Override - public HttpClient createHttpClient() { - return client; - } - - @Override - public HttpMethod createMethod(final String newType, final String newUri) { - type = newType; - uri = newUri; - return method; - } - }; - - connector.validation = new RESTValidationStrategy(); - connector.setAdminCredentials("admin", "adminpass"); - connector.setControllerAddress("localhost"); - } - - @Test(expected = CloudstackRESTException.class) - public void testExecuteLoginWithoutHostname() throws CloudstackRESTException { - connector.setControllerAddress(null); - connector.validation.login(RESTServiceConnector.protocol, client); - } - - @Test(expected = CloudstackRESTException.class) - public void testExecuteLoginWithoutCredentials() throws CloudstackRESTException { - method = mock(PutMethod.class); - connector.setAdminCredentials(null, null); - connector.validation.login(RESTServiceConnector.protocol, client); - } - - @Test(expected = CloudstackRESTException.class) - public void testExecuteUpdateObjectWithoutHostname() throws CloudstackRESTException { - method = mock(PutMethod.class); - connector.setControllerAddress(null); - connector.executeUpdateObject(new String(), "/", Collections.<String, String> emptyMap()); - } - - @Test(expected = CloudstackRESTException.class) - public void testExecuteUpdateObjectWithoutCredentials() throws CloudstackRESTException { - method = mock(PutMethod.class); - connector.setAdminCredentials(null, null); - connector.executeUpdateObject(new String(), "/", Collections.<String, String> emptyMap()); - } - - @Test(expected = CloudstackRESTException.class) - public void testExecuteCreateObjectWithoutHostname() throws CloudstackRESTException { - method = mock(PostMethod.class); - connector.setControllerAddress(null); - connector.executeCreateObject(new String(), String.class, "/", Collections.<String, String> emptyMap()); - } - - @Test(expected = CloudstackRESTException.class) - public void testExecuteCreateObjectWithoutCredentials() throws CloudstackRESTException { - method = mock(PostMethod.class); - connector.setAdminCredentials(null, null); - connector.executeCreateObject(new String(), String.class, "/", Collections.<String, String> emptyMap()); - } - - @Test(expected = CloudstackRESTException.class) - public void testExecuteDeleteObjectWithoutHostname() throws CloudstackRESTException { - method = mock(DeleteMethod.class); - connector.setControllerAddress(null); - connector.executeDeleteObject("/"); - } - - @Test(expected = CloudstackRESTException.class) - public void testExecuteDeleteObjectWithoutCredentials() throws CloudstackRESTException { - method = mock(DeleteMethod.class); - connector.setAdminCredentials(null, null); - connector.executeDeleteObject("/"); - } - - @Test(expected = CloudstackRESTException.class) - public void testExecuteRetrieveObjectWithoutHostname() throws CloudstackRESTException { - method = mock(GetMethod.class); - connector.setControllerAddress(null); - connector.executeRetrieveObject(String.class, "/", Collections.<String, String> emptyMap()); - } - - @Test(expected = CloudstackRESTException.class) - public void testExecuteRetrieveObjectWithoutCredentials() throws CloudstackRESTException { - method = mock(GetMethod.class); - connector.setAdminCredentials(null, null); - connector.executeRetrieveObject(String.class, "/", Collections.<String, String> emptyMap()); - } - - @Test - public void testExecuteMethod() throws CloudstackRESTException { - final GetMethod gm = mock(GetMethod.class); - - when(gm.getStatusCode()).thenReturn(HttpStatus.SC_OK); - connector.executeMethod(gm); - verify(gm, times(1)).getStatusCode(); - } - - @Test(expected = CloudstackRESTException.class) - public void testExecuteMethodWithLogin() throws CloudstackRESTException, HttpException, IOException { - final GetMethod gm = mock(GetMethod.class); - when(client.executeMethod((HttpMethod)any())).thenThrow(new HttpException()); - when(gm.getStatusCode()).thenReturn(HttpStatus.SC_UNAUTHORIZED).thenReturn(HttpStatus.SC_UNAUTHORIZED); - connector.executeMethod(gm); - verify(gm, times(1)).getStatusCode(); - } - - /* Bit of a roundabout way to ensure that login is called after an un authorized result - * It not possible to properly mock login() - */ - public void testExecuteMethodWithLoginSucced2ndAttempt() throws CloudstackRESTException, HttpException, IOException { - // Prepare - final GetMethod gm = mock(GetMethod.class); - when(gm.getStatusCode()).thenReturn(HttpStatus.SC_UNAUTHORIZED).thenReturn(HttpStatus.SC_UNAUTHORIZED); - - final RESTValidationStrategy previousValidationStrategy = connector.validation; - connector.validation = new RESTValidationStrategy(){ - @Override - protected void login(final String protocol, final HttpClient client) - throws CloudstackRESTException { - // Do nothing - } - }; - connector.setAdminCredentials("admin", "adminpass"); - connector.setControllerAddress("localhost"); - - // Execute - connector.executeMethod(gm); - // Leave mock object as is was - connector.validation = previousValidationStrategy; - - // Assert/verify - verify(gm, times(2)).getStatusCode(); - } - - @Test - public void testExecuteCreateObject() throws CloudstackRESTException, IOException { - JsonEntity ls = new JsonEntity(); - method = mock(PostMethod.class); - when(method.getStatusCode()).thenReturn(HttpStatus.SC_CREATED); - when(method.getResponseBodyAsString()).thenReturn(UUID_JSON_RESPONSE); - ls = connector.executeCreateObject(ls, JsonEntity.class, "/", Collections.<String, String> emptyMap()); - assertTrue(UUID.equals(ls.getUuid())); - verify(method, times(1)).releaseConnection(); - - } - - @Test(expected = CloudstackRESTException.class) - public void testExecuteCreateObjectFailure() throws CloudstackRESTException, IOException { - JsonEntity ls = new JsonEntity(); - method = mock(PostMethod.class); - when(method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR); - final Header header = mock(Header.class); - when(header.getValue()).thenReturn("text/html"); - when(method.getResponseHeader("Content-Type")).thenReturn(header); - when(method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later."); - when(method.isRequestSent()).thenReturn(true); - try { - ls = connector.executeCreateObject(ls, JsonEntity.class, "/", Collections.<String, String> emptyMap()); - } finally { - verify(method, times(1)).releaseConnection(); - } - } - - @Test(expected = CloudstackRESTException.class) - public void testExecuteCreateObjectException() throws CloudstackRESTException, IOException { - JsonEntity ls = new JsonEntity(); - when(client.executeMethod((HttpMethod)any())).thenThrow(new HttpException()); - method = mock(PostMethod.class); - when(method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR); - final Header header = mock(Header.class); - when(header.getValue()).thenReturn("text/html"); - when(method.getResponseHeader("Content-Type")).thenReturn(header); - when(method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later."); - try { - ls = connector.executeCreateObject(ls, JsonEntity.class, "/", Collections.<String, String> emptyMap()); - } finally { - verify(method, times(1)).releaseConnection(); - } - } - - @Test - public void testExecuteUpdateObject() throws CloudstackRESTException, IOException { - final JsonEntity ls = new JsonEntity(); - method = mock(PutMethod.class); - when(method.getStatusCode()).thenReturn(HttpStatus.SC_OK); - connector.executeUpdateObject(ls, "/", Collections.<String, String> emptyMap()); - verify(method, times(1)).releaseConnection(); - verify(client, times(1)).executeMethod(method); - } - - @Test(expected = CloudstackRESTException.class) - public void testExecuteUpdateObjectFailure() throws CloudstackRESTException, IOException { - final JsonEntity ls = new JsonEntity(); - method = mock(PutMethod.class); - when(method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR); - final Header header = mock(Header.class); - when(header.getValue()).thenReturn("text/html"); - when(method.getResponseHeader("Content-Type")).thenReturn(header); - when(method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later."); - when(method.isRequestSent()).thenReturn(true); - try { - connector.executeUpdateObject(ls, "/", Collections.<String, String> emptyMap()); - } finally { - verify(method, times(1)).releaseConnection(); - } - } - - @Test(expected = CloudstackRESTException.class) - public void testExecuteUpdateObjectException() throws CloudstackRESTException, IOException { - final JsonEntity ls = new JsonEntity(); - method = mock(PutMethod.class); - when(method.getStatusCode()).thenReturn(HttpStatus.SC_OK); - when(client.executeMethod((HttpMethod)any())).thenThrow(new IOException()); - try { - connector.executeUpdateObject(ls, "/", Collections.<String, String> emptyMap()); - } finally { - verify(method, times(1)).releaseConnection(); - } - } - - @Test - public void testExecuteDeleteObject() throws CloudstackRESTException, IOException { - method = mock(DeleteMethod.class); - when(method.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT); - connector.executeDeleteObject("/"); - verify(method, times(1)).releaseConnection(); - verify(client, times(1)).executeMethod(method); - } - - @Test(expected = CloudstackRESTException.class) - public void testExecuteDeleteObjectFailure() throws CloudstackRESTException, IOException { - method = mock(DeleteMethod.class); - when(method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR); - final Header header = mock(Header.class); - when(header.getValue()).thenReturn("text/html"); - when(method.getResponseHeader("Content-Type")).thenReturn(header); - when(method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later."); - when(method.isRequestSent()).thenReturn(true); - try { - connector.executeDeleteObject("/"); - } finally { - verify(method, times(1)).releaseConnection(); - } - } - - @Test(expected = CloudstackRESTException.class) - public void testExecuteDeleteObjectException() throws CloudstackRESTException, IOException { - method = mock(DeleteMethod.class); - when(method.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT); - when(client.executeMethod((HttpMethod)any())).thenThrow(new HttpException()); - try { - connector.executeDeleteObject("/"); - } finally { - verify(method, times(1)).releaseConnection(); - } - } - - @Test - public void testExecuteRetrieveObject() throws CloudstackRESTException, IOException { - method = mock(GetMethod.class); - when(method.getStatusCode()).thenReturn(HttpStatus.SC_OK); - when(method.getResponseBodyAsString()).thenReturn(UUID_JSON_RESPONSE); - connector.executeRetrieveObject(JsonEntity.class, "/", Collections.<String, String> emptyMap()); - verify(method, times(1)).releaseConnection(); - verify(client, times(1)).executeMethod(method); - } - - @Test(expected = CloudstackRESTException.class) - public void testExecuteRetrieveObjectFailure() throws CloudstackRESTException, IOException { - method = mock(GetMethod.class); - when(method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR); - when(method.getResponseBodyAsString()).thenReturn(UUID_JSON_RESPONSE); - final Header header = mock(Header.class); - when(header.getValue()).thenReturn("text/html"); - when(method.getResponseHeader("Content-Type")).thenReturn(header); - when(method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later."); - when(method.isRequestSent()).thenReturn(true); - try { - connector.executeRetrieveObject(JsonEntity.class, "/", Collections.<String, String> emptyMap()); - } finally { - verify(method, times(1)).releaseConnection(); - } - } - - @Test(expected = CloudstackRESTException.class) - public void testExecuteRetrieveObjectException() throws CloudstackRESTException, IOException { - method = mock(GetMethod.class); - when(method.getStatusCode()).thenReturn(HttpStatus.SC_OK); - when(method.getResponseBodyAsString()).thenReturn(UUID_JSON_RESPONSE); - when(client.executeMethod((HttpMethod)any())).thenThrow(new HttpException()); - try { - connector.executeRetrieveObject(JsonEntity.class, "/", Collections.<String, String> emptyMap()); - } finally { - verify(method, times(1)).releaseConnection(); - } - } - -} - -class JsonEntity { - private String displayName; - private String uuid; - private String href; - private String schema; - - public String getDisplayName() { - return displayName; - } - - public void setDisplayName(final String displayName) { - this.displayName = displayName; - } - - public String getUuid() { - return uuid; - } - - public void setUuid(final String uuid) { - this.uuid = uuid; - } - - public String getHref() { - return href; - } - - public void setHref(final String href) { - this.href = href; - } - - public String getSchema() { - return schema; - } - - public void setSchema(final String schema) { - this.schema = schema; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/test/com/cloud/utils/ssh/SSHKeysHelperTest.java ---------------------------------------------------------------------- diff --git a/utils/test/com/cloud/utils/ssh/SSHKeysHelperTest.java b/utils/test/com/cloud/utils/ssh/SSHKeysHelperTest.java deleted file mode 100644 index a3daf91..0000000 --- a/utils/test/com/cloud/utils/ssh/SSHKeysHelperTest.java +++ /dev/null @@ -1,73 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils.ssh; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -public class SSHKeysHelperTest { - @Test - public void rsaKeyTest() { - String rsaKey = - "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC2D2Cs0XAEqm+ajJpumIPrMpKp0CWtIW+8ZY2/MJCW" - + "hge1eY18u9I3PPnkMVJsTOaN0wQojjw4AkKgKjNZXA9wyUq56UyN/stmipu8zifWPgxQGDRkuzzZ6buk" - + "ef8q2Awjpo8hv5/0SRPJxQLEafESnUP+Uu/LUwk5VVC7PHzywJRUGFuzDl/uT72+6hqpL2YpC6aTl4/P" - + "2eDvUQhCdL9dBmUSFX8ftT53W1jhsaQl7mPElVgSCtWz3IyRkogobMPrpJW/IPKEiojKIuvNoNv4CDR6" - + "ybeVjHOJMb9wi62rXo+CzUsW0Y4jPOX/OykAm5vrNOhQhw0aaBcv5XVv8BRX test@testkey"; - String storedRsaKey = - "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC2D2Cs0XAEqm+ajJpumIPrMpKp0CWtIW+8ZY2/MJCW" - + "hge1eY18u9I3PPnkMVJsTOaN0wQojjw4AkKgKjNZXA9wyUq56UyN/stmipu8zifWPgxQGDRkuzzZ6buk" - + "ef8q2Awjpo8hv5/0SRPJxQLEafESnUP+Uu/LUwk5VVC7PHzywJRUGFuzDl/uT72+6hqpL2YpC6aTl4/P" - + "2eDvUQhCdL9dBmUSFX8ftT53W1jhsaQl7mPElVgSCtWz3IyRkogobMPrpJW/IPKEiojKIuvNoNv4CDR6" + "ybeVjHOJMb9wi62rXo+CzUsW0Y4jPOX/OykAm5vrNOhQhw0aaBcv5XVv8BRX"; - String parsedKey = SSHKeysHelper.getPublicKeyFromKeyMaterial(rsaKey); - String fingerprint = SSHKeysHelper.getPublicKeyFingerprint(parsedKey); - - assertTrue(storedRsaKey.equals(parsedKey)); - assertTrue("f6:96:3f:f4:78:f7:80:11:6c:f8:e3:2b:40:20:f1:14".equals(fingerprint)); - - } - - @Test - public void dsaKeyTest() { - String dssKey = - "ssh-dss AAAAB3NzaC1kc3MAAACBALbaewDnzZ5AcGbZno7VW1m7Si3Q+yEANXZioVupfSwOP0q9aP2iV" - + "tyqq575JnUVZXMDR2Gr254F/qCJ0TKAvucN0gcd2XslX4jBcu1Z7s7YZf6d7fC58k0NE6/keokJNKhQO" - + "i56iirRzSA/YFrD64mzfq6rEmai0q7GjGGP0RT1AAAAFQDO5++6JonyqnoRkV9Yl1OaEOPjVwAAAIAYA" - + "tqtKtU/INlTIuL3wt3nyKzwPUnz3fqxP5Ger3OlRZsOahalTFt2OF5jGGmCunyBTRteOetZObr0QhUIF" - + "4bSDr6UiYYYbH1ES0ws/t1mDIeTh3UUHV1QYACN6c07FKyKLMtB9AthiG2FMLKCEedG3NeXItuNzsuQD" - + "+n/K1rzMAAAAIBi5SM4pFPiB7BvTZvARV56vrG5QNgWVazSwbwgl/EACiWYbRauHDUQA9f+Rq+ayWcsR" - + "os1CD+Q81y9SmlQaZVKkSPZLxXfu5bi3s4o431xjilhZdt4vKbj2pK364IjghJPNBBfmRXzlj9awKxr/" + "UebZcBgNRyeky7VZSbbF2jQSQ== test key"; - String storedDssKey = - "ssh-dss AAAAB3NzaC1kc3MAAACBALbaewDnzZ5AcGbZno7VW1m7Si3Q+yEANXZioVupfSwOP0q9aP2iV" - + "tyqq575JnUVZXMDR2Gr254F/qCJ0TKAvucN0gcd2XslX4jBcu1Z7s7YZf6d7fC58k0NE6/keokJNKhQO" - + "i56iirRzSA/YFrD64mzfq6rEmai0q7GjGGP0RT1AAAAFQDO5++6JonyqnoRkV9Yl1OaEOPjVwAAAIAYA" - + "tqtKtU/INlTIuL3wt3nyKzwPUnz3fqxP5Ger3OlRZsOahalTFt2OF5jGGmCunyBTRteOetZObr0QhUIF" - + "4bSDr6UiYYYbH1ES0ws/t1mDIeTh3UUHV1QYACN6c07FKyKLMtB9AthiG2FMLKCEedG3NeXItuNzsuQD" - + "+n/K1rzMAAAAIBi5SM4pFPiB7BvTZvARV56vrG5QNgWVazSwbwgl/EACiWYbRauHDUQA9f+Rq+ayWcsR" - + "os1CD+Q81y9SmlQaZVKkSPZLxXfu5bi3s4o431xjilhZdt4vKbj2pK364IjghJPNBBfmRXzlj9awKxr/" + "UebZcBgNRyeky7VZSbbF2jQSQ=="; - String parsedKey = SSHKeysHelper.getPublicKeyFromKeyMaterial(dssKey); - String fingerprint = SSHKeysHelper.getPublicKeyFingerprint(parsedKey); - - assertTrue(storedDssKey.equals(parsedKey)); - assertTrue("fc:6e:ef:31:93:f8:92:2b:a9:03:c7:06:90:f5:ec:bb".equals(fingerprint)); - - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/test/com/cloud/utils/testcase/Log4jEnabledTestCase.java ---------------------------------------------------------------------- diff --git a/utils/test/com/cloud/utils/testcase/Log4jEnabledTestCase.java b/utils/test/com/cloud/utils/testcase/Log4jEnabledTestCase.java deleted file mode 100644 index 51cde2c..0000000 --- a/utils/test/com/cloud/utils/testcase/Log4jEnabledTestCase.java +++ /dev/null @@ -1,58 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils.testcase; - -import java.io.File; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.Random; - -import junit.framework.TestCase; - -import org.apache.log4j.xml.DOMConfigurator; - -public class Log4jEnabledTestCase extends TestCase { - @Override - protected void setUp() { - URL configUrl = System.class.getResource("/conf/log4j-cloud.xml"); - if (configUrl != null) { - System.out.println("Configure log4j using log4j-cloud.xml"); - - try { - File file = new File(configUrl.toURI()); - - System.out.println("Log4j configuration from : " + file.getAbsolutePath()); - DOMConfigurator.configureAndWatch(file.getAbsolutePath(), 10000); - } catch (URISyntaxException e) { - System.out.println("Unable to convert log4j configuration Url to URI"); - } - } else { - System.out.println("Configure log4j with default properties"); - } - } - - public static int getRandomMilliseconds(int rangeLo, int rangeHi) { - int i = new Random().nextInt(); - - long pos = (long)i - (long)Integer.MIN_VALUE; - long iRange = (long)Integer.MAX_VALUE - (long)Integer.MIN_VALUE; - return rangeLo + (int)((rangeHi - rangeLo) * pos / iRange); - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/test/com/cloud/utils/testcase/NioTest.java ---------------------------------------------------------------------- diff --git a/utils/test/com/cloud/utils/testcase/NioTest.java b/utils/test/com/cloud/utils/testcase/NioTest.java deleted file mode 100644 index fc16684..0000000 --- a/utils/test/com/cloud/utils/testcase/NioTest.java +++ /dev/null @@ -1,216 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils.testcase; - -import java.nio.channels.ClosedChannelException; -import java.util.Random; - -import junit.framework.TestCase; - -import org.apache.log4j.Logger; -import org.junit.Assert; - -import com.cloud.utils.nio.HandlerFactory; -import com.cloud.utils.nio.Link; -import com.cloud.utils.nio.NioClient; -import com.cloud.utils.nio.NioServer; -import com.cloud.utils.nio.Task; -import com.cloud.utils.nio.Task.Type; - -/** - * - * - * - * - */ - -public class NioTest extends TestCase { - - private static final Logger s_logger = Logger.getLogger(NioTest.class); - - private NioServer _server; - private NioClient _client; - - private Link _clientLink; - - private int _testCount; - private int _completedCount; - - private boolean isTestsDone() { - boolean result; - synchronized (this) { - result = (_testCount == _completedCount); - } - return result; - } - - private void getOneMoreTest() { - synchronized (this) { - _testCount++; - } - } - - private void oneMoreTestDone() { - synchronized (this) { - _completedCount++; - } - } - - @Override - public void setUp() { - s_logger.info("Test"); - - _testCount = 0; - _completedCount = 0; - - _server = new NioServer("NioTestServer", 7777, 5, new NioTestServer()); - _server.start(); - - _client = new NioClient("NioTestServer", "127.0.0.1", 7777, 5, new NioTestClient()); - _client.start(); - - while (_clientLink == null) { - try { - s_logger.debug("Link is not up! Waiting ..."); - Thread.sleep(1000); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - - @Override - public void tearDown() { - while (!isTestsDone()) { - try { - s_logger.debug(this._completedCount + "/" + this._testCount + " tests done. Waiting for completion"); - Thread.sleep(1000); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - stopClient(); - stopServer(); - } - - protected void stopClient() { - _client.stop(); - s_logger.info("Client stopped."); - } - - protected void stopServer() { - _server.stop(); - s_logger.info("Server stopped."); - } - - protected void setClientLink(Link link) { - _clientLink = link; - } - - Random randomGenerator = new Random(); - - byte[] _testBytes; - - public void testConnection() { - _testBytes = new byte[1000000]; - randomGenerator.nextBytes(_testBytes); - try { - getOneMoreTest(); - _clientLink.send(_testBytes); - s_logger.info("Client: Data sent"); - getOneMoreTest(); - _clientLink.send(_testBytes); - s_logger.info("Client: Data sent"); - } catch (ClosedChannelException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - protected void doServerProcess(byte[] data) { - oneMoreTestDone(); - Assert.assertArrayEquals(_testBytes, data); - s_logger.info("Verify done."); - } - - public class NioTestClient implements HandlerFactory { - - @Override - public Task create(Type type, Link link, byte[] data) { - return new NioTestClientHandler(type, link, data); - } - - public class NioTestClientHandler extends Task { - - public NioTestClientHandler(Type type, Link link, byte[] data) { - super(type, link, data); - } - - @Override - public void doTask(final Task task) { - if (task.getType() == Task.Type.CONNECT) { - s_logger.info("Client: Received CONNECT task"); - setClientLink(task.getLink()); - } else if (task.getType() == Task.Type.DATA) { - s_logger.info("Client: Received DATA task"); - } else if (task.getType() == Task.Type.DISCONNECT) { - s_logger.info("Client: Received DISCONNECT task"); - stopClient(); - } else if (task.getType() == Task.Type.OTHER) { - s_logger.info("Client: Received OTHER task"); - } - } - - } - } - - public class NioTestServer implements HandlerFactory { - - @Override - public Task create(Type type, Link link, byte[] data) { - return new NioTestServerHandler(type, link, data); - } - - public class NioTestServerHandler extends Task { - - public NioTestServerHandler(Type type, Link link, byte[] data) { - super(type, link, data); - } - - @Override - public void doTask(final Task task) { - if (task.getType() == Task.Type.CONNECT) { - s_logger.info("Server: Received CONNECT task"); - } else if (task.getType() == Task.Type.DATA) { - s_logger.info("Server: Received DATA task"); - doServerProcess(task.getData()); - } else if (task.getType() == Task.Type.DISCONNECT) { - s_logger.info("Server: Received DISCONNECT task"); - stopServer(); - } else if (task.getType() == Task.Type.OTHER) { - s_logger.info("Server: Received OTHER task"); - } - } - - } - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/test/com/cloud/utils/xmlobject/TestXmlObject.java ---------------------------------------------------------------------- diff --git a/utils/test/com/cloud/utils/xmlobject/TestXmlObject.java b/utils/test/com/cloud/utils/xmlobject/TestXmlObject.java deleted file mode 100644 index faaf980..0000000 --- a/utils/test/com/cloud/utils/xmlobject/TestXmlObject.java +++ /dev/null @@ -1,53 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils.xmlobject; - -import org.junit.Test; - -public class TestXmlObject { - - void p(String str) { - System.out.println(str); - } - - @Test - public void test() { - - // deprecated, since we no longer use component.xml.in any more - /* - XmlObject xo = XmlObjectParser.parseFromFile("z:/components.xml.in"); - p(xo.getTag()); - p((String) xo.get("system-integrity-checker.checker").toString()); - List<XmlObject> lst = xo.get("management-server.adapters"); - for (XmlObject x : lst) { - List<XmlObject> lst1 = x.getAsList("adapter"); - for (XmlObject y : lst1) { - p(y.toString()); - } - } - */ - - XmlObject xml = new XmlObject("vlan").putElement("vlan-id", String.valueOf(19)).putElement("tagged", - new XmlObject("teng").putElement("name", "0/0") - ).putElement("shutdown", "false"); - System.out.println(xml.toString()); - } - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/test/com/cloud/utils/xmlobject/TestXmlObject2.java ---------------------------------------------------------------------- diff --git a/utils/test/com/cloud/utils/xmlobject/TestXmlObject2.java b/utils/test/com/cloud/utils/xmlobject/TestXmlObject2.java deleted file mode 100644 index 9a27ca1..0000000 --- a/utils/test/com/cloud/utils/xmlobject/TestXmlObject2.java +++ /dev/null @@ -1,54 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils.xmlobject; - -import org.junit.Test; - -public class TestXmlObject2 { - void p(String str) { - System.out.println(str); - } - - XmlObject xo(String name) { - return new XmlObject(name); - } - - @Test - public void test() { - XmlObject root = new XmlObject("test"); - root.putElement("key1", "value1").putElement("key2", "value2"); - p(root.dump()); - - XmlObject c1 = new XmlObject("child1"); - XmlObject c2 = new XmlObject("child2"); - c2.putElement("ckey1", "value1"); - c1.putElement(c2.getTag(), c2); - root.putElement(c1.getTag(), c1); - p(root.dump()); - - root = - xo("test2").putElement("key1", "value1") - .putElement("child1", xo("child1").setText("yyy")) - .putElement("child1", xo("child1").putElement("child2", xo("child2").putElement("child3", xo("child3").putElement("key3", "value3").setText("xxxxx")))); - - p(root.dump()); - } - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/test/org/apache/cloudstack/utils/imagestore/ImageStoreUtilTest.java ---------------------------------------------------------------------- diff --git a/utils/test/org/apache/cloudstack/utils/imagestore/ImageStoreUtilTest.java b/utils/test/org/apache/cloudstack/utils/imagestore/ImageStoreUtilTest.java deleted file mode 100644 index ace765a..0000000 --- a/utils/test/org/apache/cloudstack/utils/imagestore/ImageStoreUtilTest.java +++ /dev/null @@ -1,54 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package org.apache.cloudstack.utils.imagestore; - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.UUID; - -import org.junit.Assert; -import org.junit.Test; - -public class ImageStoreUtilTest { - - @Test - public void testgeneratePostUploadUrl() throws MalformedURLException { - String ssvmdomain = "*.realhostip.com"; - String ipAddress = "10.147.28.14"; - String uuid = UUID.randomUUID().toString(); - - //ssvm domain is not set - String url = ImageStoreUtil.generatePostUploadUrl(null, ipAddress, uuid); - assertPostUploadUrl(url, ipAddress, uuid); - - //ssvm domain is set to empty value - url = ImageStoreUtil.generatePostUploadUrl("", ipAddress, uuid); - assertPostUploadUrl(url, ipAddress, uuid); - - //ssvm domain is set to a valid value - url = ImageStoreUtil.generatePostUploadUrl(ssvmdomain, ipAddress, uuid); - assertPostUploadUrl(url, ipAddress.replace(".", "-") + ssvmdomain.substring(1), uuid); - } - - private void assertPostUploadUrl(String urlStr, String domain, String uuid) throws MalformedURLException { - URL url = new URL(urlStr); - Assert.assertNotNull(url); - Assert.assertEquals(url.getHost(), domain); - Assert.assertEquals(url.getPath(), "/upload/" + uuid); - } - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/test/resources/com/cloud/utils/QualifierTestContext.xml ---------------------------------------------------------------------- diff --git a/utils/test/resources/com/cloud/utils/QualifierTestContext.xml b/utils/test/resources/com/cloud/utils/QualifierTestContext.xml deleted file mode 100644 index 39f494b..0000000 --- a/utils/test/resources/com/cloud/utils/QualifierTestContext.xml +++ /dev/null @@ -1,38 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - ---> -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:context="http://www.springframework.org/schema/context" - xmlns:tx="http://www.springframework.org/schema/tx" - xmlns:aop="http://www.springframework.org/schema/aop" - xsi:schemaLocation="http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans-3.0.xsd - http://www.springframework.org/schema/tx - http://www.springframework.org/schema/tx/spring-tx-3.0.xsd - http://www.springframework.org/schema/aop - http://www.springframework.org/schema/aop/spring-aop-3.0.xsd - http://www.springframework.org/schema/context - http://www.springframework.org/schema/context/spring-context-3.0.xsd"> - <context:annotation-config /> - <context:component-scan base-package="org.apache.cloudstack, com.cloud" /> - -</beans> http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/test/resources/com/cloud/utils/db/transactionContextBuilderTest.xml ---------------------------------------------------------------------- diff --git a/utils/test/resources/com/cloud/utils/db/transactionContextBuilderTest.xml b/utils/test/resources/com/cloud/utils/db/transactionContextBuilderTest.xml deleted file mode 100644 index 81ca058..0000000 --- a/utils/test/resources/com/cloud/utils/db/transactionContextBuilderTest.xml +++ /dev/null @@ -1,48 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - ---> -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:context="http://www.springframework.org/schema/context" - xmlns:tx="http://www.springframework.org/schema/tx" - xmlns:aop="http://www.springframework.org/schema/aop" - xsi:schemaLocation="http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans-3.0.xsd - http://www.springframework.org/schema/tx - http://www.springframework.org/schema/tx/spring-tx-3.0.xsd - http://www.springframework.org/schema/aop - http://www.springframework.org/schema/aop/spring-aop-3.0.xsd - http://www.springframework.org/schema/context - http://www.springframework.org/schema/context/spring-context-3.0.xsd"> - <context:annotation-config /> - <context:component-scan base-package="org.apache.cloudstack, com.cloud" /> - - <aop:config proxy-target-class="true"> - <aop:aspect id="dbContextBuilder" ref="transactionContextBuilder"> - <aop:pointcut id="captureAnyMethod" - expression="execution(* *(..))" /> - <aop:around pointcut-ref="captureAnyMethod" method="AroundAnyMethod"/> - </aop:aspect> - </aop:config> - - <bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder" /> - -</beans> http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/test/resources/log4j.xml ---------------------------------------------------------------------- diff --git a/utils/test/resources/log4j.xml b/utils/test/resources/log4j.xml deleted file mode 100755 index cdae2fa..0000000 --- a/utils/test/resources/log4j.xml +++ /dev/null @@ -1,118 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - ---> -<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> - -<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false"> - - <throwableRenderer class="com.cloud.utils.log.CglibThrowableRenderer"/> - <!-- ================================= --> - <!-- Preserve messages in a local file --> - <!-- ================================= --> - - <!-- A regular appender FIXME implement code that will close/reopen logs on SIGHUP by logrotate FIXME make the paths configurable using the build system --> -<!-- <appender name="FILE" class="org.apache.log4j.rolling.RollingFileAppender"> - <param name="Append" value="true"/> - <param name="Threshold" value="TRACE"/> - <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy"> - <param name="FileNamePattern" value="@MSLOG@.%d{yyyy-MM-dd}.gz"/> - <param name="ActiveFileName" value="@MSLOG@"/> - </rollingPolicy> - <layout class="org.apache.log4j.EnhancedPatternLayout"> - <param name="ConversionPattern" value="%d{ISO8601} %-5p [%c{3}] (%t:%x) %m%n"/> - </layout> - </appender> - --> - <!-- - <appender name="APISERVER" class="org.apache.log4j.rolling.RollingFileAppender"> - <param name="Append" value="true"/> - <param name="Threshold" value="TRACE"/> - <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy"> - <param name="FileNamePattern" value="@APISERVERLOG@.%d{yyyy-MM-dd}.gz"/> - <param name="ActiveFileName" value="@APISERVERLOG@"/> - </rollingPolicy> - <layout class="org.apache.log4j.EnhancedPatternLayout"> - <param name="ConversionPattern" value="%d{ISO8601} %-5p [%c{3}] (%t:%x) %m%n"/> - </layout> - </appender> - --> - - - <!-- ============================== --> - <!-- Append warnings+ to the syslog if it is listening on UDP port FIXME make sysloghost configurable! --> - <!-- ============================== --> -<!-- - <appender name="SYSLOG" class="org.apache.log4j.net.SyslogAppender"> - <param name="Threshold" value="WARN"/> - <param name="SyslogHost" value="localhost"/> - <param name="Facility" value="LOCAL6"/> - <layout class="org.apache.log4j.PatternLayout"> - <param name="ConversionPattern" value="%-5p [%c{3}] (%t:%x) %m%n"/> - </layout> - </appender> ---> - <!-- ============================== --> - <!-- Append messages to the console --> - <!-- ============================== --> - - <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> - <param name="Target" value="System.out"/> - <param name="Threshold" value="TRACE"/> - <layout class="org.apache.log4j.PatternLayout"> - <param name="ConversionPattern" value="%d{ISO8601} %-5p [%c{3}] (%t:%x) %m%n"/> - </layout> - </appender> - - <!-- ================ --> - <!-- Limit categories --> - <!-- ================ --> - - <category name="com.cloud"> - <priority value="DEBUG"/> - </category> - - <!-- Limit the org.apache category to INFO as its DEBUG is verbose --> - <category name="org.apache"> - <priority value="INFO"/> - </category> - - <category name="org"> - <priority value="INFO"/> - </category> - - <category name="net"> - <priority value="INFO"/> - </category> - - <category name="apiserver.com.cloud"> - <priority value="DEBUG"/> - </category> - - <!-- ======================= --> - <!-- Setup the Root category --> - <!-- ======================= --> - - <root> - <level value="INFO"/> - <appender-ref ref="CONSOLE"/> - </root> - -</log4j:configuration> http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/test/resources/testContext.xml ---------------------------------------------------------------------- diff --git a/utils/test/resources/testContext.xml b/utils/test/resources/testContext.xml deleted file mode 100644 index cb5b9b8..0000000 --- a/utils/test/resources/testContext.xml +++ /dev/null @@ -1,52 +0,0 @@ -<!-- - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - ---> -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:context="http://www.springframework.org/schema/context" - xmlns:tx="http://www.springframework.org/schema/tx" - xmlns:aop="http://www.springframework.org/schema/aop" - xsi:schemaLocation="http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans-3.0.xsd - http://www.springframework.org/schema/tx - http://www.springframework.org/schema/tx/spring-tx-3.0.xsd - http://www.springframework.org/schema/aop - http://www.springframework.org/schema/aop/spring-aop-3.0.xsd - http://www.springframework.org/schema/context - http://www.springframework.org/schema/context/spring-context-3.0.xsd"> - - <context:annotation-config /> - - <context:component-scan base-package="org.apache.cloudstack, com.cloud" /> - - <!-- - @DB support - --> - <bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder" /> - - <bean id="instantiatePostProcessor" class="com.cloud.utils.component.ComponentInstantiationPostProcessor"> - <property name="Interceptors"> - <list> - <ref bean="transactionContextBuilder" /> - </list> - </property> - </bean> - -</beans>