/** Tests if exception is thrown when we try to save without mandatory properties */ @Test public void createInvalidTest() throws CompanyServiceValidationException { Company company = new Company(); Owner o = new Owner(); o.setCompany(company); // test missing companyid try { companyService.save(company); } catch (CompanyServiceValidationException e) { assertEquals(e.getError(), MISSING_FIELD); assertEquals(e.getInfo(), COMPANYID.toString()); } // test missing address try { company.setCompanyId("1"); companyService.save(company); } catch (CompanyServiceValidationException e) { assertEquals(e.getError(), MISSING_FIELD); assertEquals(e.getInfo(), ADDRESS.toString()); } // test missing city try { company.setAddress(PREFIX_ADDRESS); companyService.save(company); } catch (CompanyServiceValidationException e) { assertEquals(e.getError(), MISSING_FIELD); assertEquals(e.getInfo(), CITY.toString()); } // test missing country try { company.setCity(PREFIX_CITY); companyService.save(company); } catch (CompanyServiceValidationException e) { assertEquals(e.getError(), MISSING_FIELD); assertEquals(e.getInfo(), COUNTRY.toString()); } // test missing name try { company.setCountry(PREFIX_COUNTRY); companyService.save(company); } catch (CompanyServiceValidationException e) { assertEquals(e.getError(), MISSING_FIELD); assertEquals(e.getInfo(), NAME.toString()); } // test if at least 1 owner is added try { company.setName(PREFIX_NAME); companyService.save(company); } catch (CompanyServiceValidationException e) { assertEquals(e.getError(), MISSING_OWNER); } // test missing owner firstname try { company.getOwners().add(o); companyService.save(company); } catch (CompanyServiceValidationException e) { assertEquals(e.getError(), MISSING_FIELD); assertEquals(e.getInfo(), OWNER_FIRSTNAME.toString()); } // test missing owner lastname try { o.setFirstName(PREFIX_FIRSTNAME); companyService.save(company); } catch (CompanyServiceValidationException e) { assertEquals(e.getError(), MISSING_FIELD); assertEquals(e.getInfo(), OWNER_LASTNAME.toString()); } // just save o.setLastName(PREFIX_LASTNAME); companyService.save(company); final String INVALID = "invalid"; // test invalid phone try { company.setPhone(INVALID); companyService.save(company); } catch (CompanyServiceValidationException e) { assertEquals(e.getError(), INVALID_PHONE_NUMBER); } // test invalid email try { company.setPhone(null); company.setEmail(INVALID); companyService.save(company); } catch (CompanyServiceValidationException e) { assertEquals(e.getError(), INVALID_EMAIL); } }
protected void sendCrashReceive() throws Exception { ServerLocator[] locators = new ServerLocator[liveServers.size()]; try { for (int i = 0; i < locators.length; i++) { locators[i] = getServerLocator(i); } ClientSessionFactory[] factories = new ClientSessionFactory[liveServers.size()]; for (int i = 0; i < factories.length; i++) { factories[i] = createSessionFactory(locators[i]); } ClientSession[] sessions = new ClientSession[liveServers.size()]; for (int i = 0; i < factories.length; i++) { sessions[i] = createSession(factories[i], true, true); sessions[i].createQueue(ADDRESS, ADDRESS, null, true); } // make sure bindings are ready before sending messages for (int i = 0; i < liveServers.size(); i++) { this.waitForBindings(liveServers.get(i).getServer(), ADDRESS.toString(), true, 1, 0, 2000); this.waitForBindings(liveServers.get(i).getServer(), ADDRESS.toString(), false, 1, 0, 2000); } ClientProducer producer = sessions[0].createProducer(ADDRESS); for (int i = 0; i < liveServers.size() * 100; i++) { ClientMessage message = sessions[0].createMessage(true); setBody(i, message); message.putIntProperty("counter", i); producer.send(message); } producer.close(); for (TestableServer liveServer : liveServers) { waitForDistribution(ADDRESS, liveServer.getServer(), 100); } for (TestableServer liveServer : liveServers) { liveServer.crash(); } ClientConsumer[] consumers = new ClientConsumer[liveServers.size()]; for (int i = 0; i < factories.length; i++) { consumers[i] = sessions[i].createConsumer(ADDRESS); sessions[i].start(); } for (int i = 0; i < 100; i++) { for (ClientConsumer consumer : consumers) { ClientMessage message = consumer.receive(1000); assertNotNull("expecting durable msg " + i, message); message.acknowledge(); } } } finally { for (ServerLocator locator : locators) { if (locator != null) { try { locator.close(); } catch (Exception e) { // ignore } } } } }
@Override public void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException { if (ignoreOperationIfServerNotActive(context, operation)) { return; } validator.validate(operation); final String attributeName = operation.require(ModelDescriptionConstants.NAME).asString(); PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)); String queueName = address.getLastElement().getValue(); if (forwardToRuntimeQueue(context, operation, RUNTIME_INSTANCE)) { return; } final ServiceName serviceName = MessagingServices.getActiveMQServiceName(address); ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName); ActiveMQServer server = ActiveMQServer.class.cast(service.getValue()); QueueControl control = QueueControl.class.cast( server.getManagementService().getResource(ResourceNames.CORE_QUEUE + queueName)); if (control == null) { throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address); } if (MESSAGE_COUNT.getName().equals(attributeName)) { context.getResult().set(control.getMessageCount()); } else if (SCHEDULED_COUNT.getName().equals(attributeName)) { context.getResult().set(control.getScheduledCount()); } else if (CONSUMER_COUNT.getName().equals(attributeName)) { context.getResult().set(control.getConsumerCount()); } else if (DELIVERING_COUNT.getName().equals(attributeName)) { context.getResult().set(control.getDeliveringCount()); } else if (MESSAGES_ADDED.getName().equals(attributeName)) { context.getResult().set(control.getMessagesAdded()); } else if (ID.getName().equals(attributeName)) { context.getResult().set(control.getID()); } else if (PAUSED.getName().equals(attributeName)) { try { context.getResult().set(control.isPaused()); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } } else if (TEMPORARY.getName().equals(attributeName)) { context.getResult().set(control.isTemporary()); } else if (EXPIRY_ADDRESS.getName().equals(attributeName)) { if (control.getExpiryAddress() != null) { context.getResult().set(control.getExpiryAddress()); } } else if (DEAD_LETTER_ADDRESS.getName().equals(attributeName)) { if (control.getDeadLetterAddress() != null) { context.getResult().set(control.getDeadLetterAddress()); } } else if (readStorageAttributes && getStorageAttributeNames().contains(attributeName)) { if (ADDRESS.getName().equals(attributeName)) { context.getResult().set(control.getAddress()); } else if (DURABLE.getName().equals(attributeName)) { context.getResult().set(control.isDurable()); } else if (FILTER.getName().equals(attributeName)) { ModelNode result = context.getResult(); String filter = control.getFilter(); if (filter != null) { result.set(filter); } } } else { throw MessagingLogger.ROOT_LOGGER.unsupportedAttribute(attributeName); } }