List of usage examples for org.springframework.util Assert isTrue
public static void isTrue(boolean expression, Supplier<String> messageSupplier)
From source file:com.opensourceagility.trafficcop.client.TrafficCopClientDemo.java
public static void main(String[] args) { // Check that we are passed two arguments - the api base url and an access token Assert.isTrue(args.length == 2, "Usage: TrafficCopClientDemo <trafficCopBaseUrl> <accessToken>"); // Construct new REST OAuth client for TrafficCop, configured with the access token TrafficCop trafficCop = new TrafficCopTemplate(args[0], args[1]); // Access a proxied service String message = trafficCop.proxiedServiceOperations().getMessage(); // Print out the message from the service System.out.println("Message returned from TrafficCop's proxied service is: " + message); }
From source file:it.inserpio.mapillary.gopro.importer.GoProTimeLapseShotsMapillaryImporter.java
public static final void main(String[] args) { try {/*from w ww.jav a2 s . c om*/ Assert.isTrue(args.length == 2, "\n\nYou need to provide 2 arguments:\n\n[1] GPX absolute file name;\n[2] Absolute directory name containing GoPro Time-Lapse Shots.\n\n"); uploadToMapillary(args[0], args[1]); System.exit(0); } catch (Exception e) { e.printStackTrace(); System.exit(-1); } }
From source file:com.athena.peacock.agent.Starter.java
/** * <pre>/* w w w . ja v a 2s . c om*/ * * </pre> * @param args */ @SuppressWarnings("resource") public static void main(String[] args) { int rand = (int) (Math.random() * 100) % 50; System.setProperty("random.seconds", Integer.toString(rand)); String configFile = null; try { configFile = PropertyUtil.getProperty(PeacockConstant.CONFIG_FILE_KEY); } catch (Exception e) { // nothing to do. } finally { if (StringUtils.isEmpty(configFile)) { configFile = "/peacock/agent/config/agent.conf"; } } /** * ${peacock.agent.config.file.name} ?? load ? ?? ? ? ? . */ String errorMsg = "\n\"" + configFile + "\" file does not exist or cannot read.\n" + "Please check \"" + configFile + "\" file exists and can read."; Assert.isTrue(AgentConfigUtil.exception == null, errorMsg); Assert.notNull(AgentConfigUtil.getConfig(PeacockConstant.SERVER_IP), "ServerIP cannot be empty."); Assert.notNull(AgentConfigUtil.getConfig(PeacockConstant.SERVER_PORT), "ServerPort cannot be empty."); /** * Agent ID ?? ${peacock.agent.agent.file.name} ? ?, * ?? ? Agent ID ? ?? . */ String agentFile = null; String agentId = null; try { agentFile = PropertyUtil.getProperty(PeacockConstant.AGENT_ID_FILE_KEY); } catch (Exception e) { // nothing to do. } finally { if (StringUtils.isEmpty(agentFile)) { agentFile = "/peacock/agent/.agent"; } } File file = new File(agentFile); boolean isNew = false; if (file.exists()) { try { agentId = IOUtils.toString(file.toURI()); // ? ? agent ID agent ID? ? 36? ? ?. if (StringUtils.isEmpty(agentId) || agentId.length() != 36) { throw new IOException(); } } catch (IOException e) { logger.error(agentFile + " file cannot read or saved invalid agent ID.", e); agentId = PeacockAgentIDGenerator.generateId(); isNew = true; } } else { agentId = PeacockAgentIDGenerator.generateId(); isNew = true; } if (isNew) { logger.info("New Agent-ID({}) be generated.", agentId); try { file.setWritable(true); OutputStreamWriter output = new OutputStreamWriter(new FileOutputStream(file)); output.write(agentId); file.setReadOnly(); IOUtils.closeQuietly(output); } catch (UnsupportedEncodingException e) { logger.error("UnsupportedEncodingException has occurred : ", e); } catch (FileNotFoundException e) { logger.error("FileNotFoundException has occurred : ", e); } catch (IOException e) { logger.error("IOException has occurred : ", e); } } // Spring Application Context Loading logger.debug("Starting application context..."); AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext( "classpath:spring/context-*.xml"); applicationContext.registerShutdownHook(); }
From source file:at.porscheinformatik.common.spring.web.extended.util.ParboiledUtils.java
public static <T> List<T> buildFromResult(ParsingResult<T> result, String resourceDescription) { Assert.notNull(result, "Got null Result while parsing template " + resourceDescription); if (result.hasErrors()) { throw new IllegalArgumentException(buildErrorMessag(result, resourceDescription)); }//from w w w .j a v a 2s . c o m Assert.isTrue(result.matched, "Template " + resourceDescription + " does not match the required format "); List<T> parts = new ArrayList<>(result.valueStack.size()); for (T part : result.valueStack) { parts.add(0, part); } return parts; }
From source file:oz.hadoop.yarn.api.utils.ConfigUtils.java
/** * Will dynamically add configuration directory to the classpath. * //from w ww .j ava 2 s . c o m * @param configurationDirectoryPath */ public static void addToClasspath(File configurationDirectoryPath) { Assert.notNull(configurationDirectoryPath, "'configurationDirectoryPath' must not be null"); Assert.isTrue(configurationDirectoryPath.exists(), "'configurationDirectoryPath' must exist"); Assert.isTrue(configurationDirectoryPath.isDirectory(), "'configurationDirectoryPath' must be a directory"); URL configUrl = null; try { configUrl = new URL("file:" + configurationDirectoryPath.getAbsolutePath() + "/"); } catch (Exception e) { throw new IllegalArgumentException("Failed to construct URL for " + configurationDirectoryPath, e); } URLClassLoader cl = (URLClassLoader) ClassLoader.getSystemClassLoader(); Method addUrlMethod = ReflectionUtils.getMethodAndMakeAccessible(URLClassLoader.class, "addURL", URL.class); try { addUrlMethod.invoke(cl, configUrl); } catch (Exception e) { throw new IllegalStateException("Failed to add URL: " + configUrl + " to the classpath", e); } }
From source file:com.smhdemo.common.query.Result.java
public Result(int row, int count, List<Object> resultList) { Assert.isTrue(count >= 0, "count < 0"); Assert.isTrue(row > 0, "row <= 0"); this.count = count; this.row = row; this.resultList = resultList; }
From source file:com.ewcms.common.query.Result.java
public Result(int row, int count, List<Object> resultList, List<Object> extList) { Assert.isTrue(count >= 0, "count < 0"); Assert.isTrue(row > 0, "row <= 0"); this.count = count; this.row = row; this.resultList = resultList; this.extList = extList; }
From source file:cat.albirar.framework.dynabean.impl.DynaBeanFactoryUtils.java
/** * Extract a dynaBean from proxy or return directly if isn't proxy. * @param dynaBean The dynabean (proxified or not) <b>REQUIRED</b> * @return The {@link DynaBeanImpl} deproxified if needed * @throws IllegalArgumentException If the dynaBean is not of the class {@link DynaBeanImpl} *///w ww . j a va 2s . co m public static DynaBeanImpl<?> deproxifyDynabean(Object dynaBean) { Object db; if (Proxy.isProxyClass(dynaBean.getClass())) { db = Proxy.getInvocationHandler(dynaBean); } else { db = dynaBean; } Assert.isTrue(DynaBeanImpl.class.isAssignableFrom(db.getClass()), "The dynaBean should to be a true dynaBean"); return (DynaBeanImpl<?>) db; }
From source file:com.audi.interview.booking.service.VehicleService.java
public Vehicle saveVehicle(Vehicle vehicle) { Assert.notNull(vehicle);/*from w ww. j a v a 2 s . c o m*/ Assert.notNull(vehicle.getColor()); Assert.notNull(vehicle.getLicensePlate()); Assert.notNull(vehicle.getModel()); Assert.notNull(vehicle.getValidTill()); // date not in the past Assert.isTrue(vehicle.getValidTill().after(new Date()), "field validTill should be at least a future date"); Assert.notNull(vehicle.getVin()); return vehicleRepository.saveAndFlush(vehicle); }
From source file:com.github.dactiv.common.unit.selenium.WebDriverFactory.java
/** * ?driverName??WebDriver./* w w w . ja v a 2 s . co m*/ * * ??firefox,ie,chrome??. * * ????Windows, IE?XWindows, ???remote driverWindows. * drivernameremote:192.168.0.2:4444:firefox, ??http://192.168.0.2:4444/wd/hub?selenium remote?. */ public static WebDriver createDriver(String driverName) { WebDriver driver = null; if (BrowserType.firefox.name().equals(driverName)) { driver = new FirefoxDriver(); } else if (BrowserType.ie.name().equals(driverName)) { driver = new InternetExplorerDriver(); } else if (BrowserType.chrome.name().equals(driverName)) { driver = new ChromeDriver(); } else if (driverName.startsWith(BrowserType.remote.name())) { String[] params = driverName.split(":"); Assert.isTrue(params.length == 4, "Remote driver is not right, accept format is \"remote:localhost:4444:firefox\", but the input is\"" + driverName + "\""); String remoteHost = params[1]; String remotePort = params[2]; String driverType = params[3]; String remoteUrl = "http://" + remoteHost + ":" + remotePort + "/wd/hub"; DesiredCapabilities cap = null; if (BrowserType.firefox.name().equals(driverType)) { cap = DesiredCapabilities.firefox(); } else if (BrowserType.ie.name().equals(driverType)) { cap = DesiredCapabilities.internetExplorer(); } else if (BrowserType.chrome.name().equals(driverType)) { cap = DesiredCapabilities.chrome(); } try { driver = new RemoteWebDriver(new URL(remoteUrl), cap); } catch (MalformedURLException e) { throw new RuntimeException(e); } } Assert.notNull(driver, "Driver could be found by name:" + driverName); return driver; }