frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); Cloud cloud = new Cloud(); Random random = new Random(); for (String s : WORDS) {
public class GamePanel extends JPanel{ //example GameObjects, these could be in a list GameObject bird = new Bird(); GameObject cloud = new Cloud(); public void paintComponent(Graphics g){ bird.drawMe(g); cloud.drawMe(g); } }
@Test(expected=CloudException.class) public void getServiceInfoByInvalidId() { StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); testCloud.getServiceInfo("foo"); }
@Test(expected=CloudException.class) public void getSingletonServiceInfoByTypeNoService() { StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); testCloud.getSingletonServiceInfoByType(StubServiceInfo.class); }
@Test public void serviceInfoNoServices() { StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); assertEquals(0, testCloud.getServiceInfos().size()); assertEquals(0, testCloud.getServiceInfos(StubServiceInfo.class).size()); }
@Test(expected=CloudException.class) public void getSingletonServiceConnectorNoMatchingServiceConnectorCreator() { // Think an app bound to a (user) service that doesn't have a corresponding // registered ServiceConnectorCreator. When user asks for singleton service connector // for another type (with a corresponding creator registered), // getSingletonServiceConnector() should throw a CloudException. BaseServiceInfo testServiceInfo = new BaseServiceInfo("user-service"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo); serviceConnectorCreators.add(new StubServiceConnectorCreator()); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); testCloud.getSingletonServiceConnector(StubServiceConnector.class, null); }
@Test(expected=CloudException.class) public void getSingletonServiceConnectorMultipleServices() { StubServiceInfo testServiceInfo1 = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubServiceInfo testServiceInfo2 = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo1, testServiceInfo2); serviceConnectorCreators.add(new StubServiceConnectorCreator()); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); testCloud.getSingletonServiceConnector(null, null); }
@Test public void serviceInfoMultipleServicesOfTheSameType() { StubServiceInfo testServiceInfo1 = new StubServiceInfo("test-id1", "test-host", 1000, "test-username", "test-password"); StubServiceInfo testServiceInfo2 = new StubServiceInfo("test-id2", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo1, testServiceInfo2); serviceConnectorCreators.add(new StubServiceConnectorCreator()); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); assertEquals(2, testCloud.getServiceInfos().size()); assertEquals(2, testCloud.getServiceInfos(StubServiceConnector.class).size()); }
@Test public void getSingletonServiceConnectorSingleService() { StubServiceInfo testServiceInfo = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo); serviceConnectorCreators.add(new StubServiceConnectorCreator()); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); StubServiceConnector connector = testCloud.getSingletonServiceConnector(null, null); assertStubService(testServiceInfo, connector, null); }
@Test public void serviceConnectorCreation() { String serviceId = "mysql-db"; CloudConnector stubCloudConnector = getTestCloudConnector(createMysqlService(serviceId)); Cloud testCloud = new Cloud(stubCloudConnector, serviceCreators); DataSource serviceConnector = testCloud.getServiceConnector(serviceId, DataSource.class, null); assertNotNull(serviceConnector); }
@Test public void serviceConnectorCreationDefaultTypeAndConfig() { StubServiceInfo testServiceInfo = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo); serviceConnectorCreators.add(new StubServiceConnectorCreator()); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); StubServiceConnector connector = testCloud.getServiceConnector(testServiceInfo.getId(), null, null); assertStubService(testServiceInfo, connector, null); }
@Test public void getSingletonServiceInfoByTypeSingleService() { StubServiceInfo testServiceInfo = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); assertNotNull(testCloud.getSingletonServiceInfoByType(StubServiceInfo.class)); }
@Test(expected=CloudException.class) public void getSingletonServiceInfoByTypeMultipleServices() { StubServiceInfo testServiceInfo1 = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubServiceInfo testServiceInfo2 = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo1, testServiceInfo2); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); testCloud.getSingletonServiceInfoByType(StubServiceInfo.class); }
@Test public void serviceConnectorCreationSpecifiedTypeAndConfig() { StubServiceInfo testServiceInfo = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo); serviceConnectorCreators.add(new StubServiceConnectorCreator()); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); StubServiceConnectorConfig config = new StubServiceConnectorConfig("test-config"); StubServiceConnector connector = testCloud.getServiceConnector(testServiceInfo.getId(), StubServiceConnector.class, config); assertStubService(testServiceInfo, connector, config); }
@Test public void servicePropsTwoServicesOfTheSameLabel() { StubServiceInfo testServiceInfo1 = new StubServiceInfo("test-id1", "test-host", 1000, "test-username", "test-password"); StubServiceInfo testServiceInfo2 = new StubServiceInfo("test-id2", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo1, testServiceInfo2); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); Properties cloudProperties = testCloud.getCloudProperties(); assertStubServiceProp("cloud.services.test-id1", testServiceInfo1, cloudProperties); assertStubServiceProp("cloud.services.test-id2", testServiceInfo2, cloudProperties); assertNull(cloudProperties.get("cloud.services.stub.connection.host")); }
@Test public void servicePropsOneServiceOfTheSameLabel() { StubServiceInfo testServiceInfo = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); Properties cloudProperties = testCloud.getCloudProperties(); assertStubServiceProp("cloud.services.test-id", testServiceInfo, cloudProperties); assertStubServiceProp("cloud.services.stub", testServiceInfo, cloudProperties); }
@Test public void servicePropsRabbit() { String serviceId = "my-rabbit"; AmqpServiceInfo rabbitServiceInfo = createRabbitService(serviceId); CloudConnector stubCloudConnector = getTestCloudConnector(rabbitServiceInfo); Cloud testCloud = new Cloud(stubCloudConnector, serviceCreators); Properties cloudProperties = testCloud.getCloudProperties(); assertRabbitProps("cloud.services.my-rabbit", rabbitServiceInfo, cloudProperties); assertRabbitProps("cloud.services.rabbitmq", rabbitServiceInfo, cloudProperties); }
@Test public void servicePropsRedis() { String serviceId = "my-redis"; RedisServiceInfo redisServiceInfo = createRedisService(serviceId); CloudConnector stubCloudConnector = getTestCloudConnector(redisServiceInfo); Cloud testCloud = new Cloud(stubCloudConnector, serviceCreators); Properties cloudProperties = testCloud.getCloudProperties(); assertBasicProps("cloud.services.my-redis", redisServiceInfo, cloudProperties); assertBasicProps("cloud.services.redis", redisServiceInfo, cloudProperties); }
@Test public void compositeServiceInfo() { StubServiceInfo testServiceInfo1 = new StubServiceInfo("test-id-1", "test-host", 1000, "test-username", "test-password"); StubServiceInfo testServiceInfo2 = new StubServiceInfo("test-id-2", "test-host", 1000, "test-username", "test-password"); ServiceInfo testCompositeServiceInfo = new StubCompositeServiceInfo("test-composite",testServiceInfo1, testServiceInfo2); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testCompositeServiceInfo); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); assertNotNull(testCloud.getServiceInfo("test-id-1")); assertNotNull(testCloud.getServiceInfo("test-id-2")); }
@Test public void getServiceInfoByValidId() { StubServiceInfo testServiceInfo1 = new StubServiceInfo("test-id1", "test-host", 1000, "test-username", "test-password"); StubServiceInfo testServiceInfo2 = new StubServiceInfo("test-id2", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo1, testServiceInfo2); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); assertEquals(testServiceInfo1, testCloud.getServiceInfo(testServiceInfo1.getId())); assertEquals(testServiceInfo2, testCloud.getServiceInfo(testServiceInfo2.getId())); }