public GrabAppCommandRunner(List<String> args) { args = new ArrayList<>(args); if(args.size() < 3) { throw new IllegalArgumentException("app grab : missing coordinates argument"); } this.coordinates = args.get(2); this.grabbingStrategy = checkPresent(GrabbingStrategy.fromCoordinates(this.coordinates), "app grab : cannot found a grabbing strategy for coordinates: " + this.coordinates); this.projectName = this.grabbingStrategy.extractProjectNameFrom(this.coordinates); this.destinationDirectoy = args.size() >= 4 ? Paths.get(args.get(3)) : standardCachedAppPath(projectName); }
@SuppressWarnings("unchecked") private List<Given> loadGivens(Map testCase) throws IOException { List<Given> givens = Lists.newArrayList(); Iterable given = checkInstanceOf("given", testCase.get("given"), Iterable.class); for (Object g : given) { Map<String, ?> given1 = (Map<String, ?>) checkInstanceOf("given", g, Map.class); if (given1.isEmpty()) { throw new IllegalArgumentException( String.format("can't load %s: a given has no properties at all", testCase)); } String firstKey = checkInstanceOf("key", given1.keySet().iterator().next(), String.class); givens.add(findLoader(given1, firstKey).load(given1)); } return givens; }
@Override public Given load(Map<String, ?> given) { List<String> uuids = newArrayList(); Object data = checkContainsKey("given", given, "uuids"); if (data instanceof String) { String s = (String) data; Iterables.addAll(uuids, Splitter.on(",").omitEmptyStrings().trimResults().split(s)); } else if (data instanceof Iterable) { Iterables.addAll(uuids, asIterableString((Iterable) data)); } else if (data != null) { throw new IllegalArgumentException("unsupported type for uuids data in " + given + ": " + data.getClass().getName() + " must be either String or Iterable."); } return new GivenUUIDGenerator(ImmutableList.copyOf(uuids)); }
protected JsonObjectLocation contextRight(Object o) { return checkPresent(rightObj.getLocations().getLocationOf(o), "can't find right context for " + o); }
@SuppressWarnings("unchecked") private List<Given> loadGivens(Map testCase) throws IOException { List<Given> givens = Lists.newArrayList(); Iterable given = checkInstanceOf("given", testCase.get("given"), Iterable.class); for (Object g : given) { Map<String, ?> given1 = (Map<String, ?>) checkInstanceOf("given", g, Map.class); if (given1.isEmpty()) { throw new IllegalArgumentException( String.format("can't load %s: a given has no properties at all", testCase)); } String firstKey = checkInstanceOf("key", given1.keySet().iterator().next(), String.class); givens.add(findLoader(given1, firstKey).load(given1)); } return givens; }
@Override public Given load(Map<String, ?> given) { List<String> uuids = newArrayList(); Object data = checkContainsKey("given", given, "uuids"); if (data instanceof String) { String s = (String) data; Iterables.addAll(uuids, Splitter.on(",").omitEmptyStrings().trimResults().split(s)); } else if (data instanceof Iterable) { Iterables.addAll(uuids, asIterableString((Iterable) data)); } else if (data != null) { throw new IllegalArgumentException("unsupported type for uuids data in " + given + ": " + data.getClass().getName() + " must be either String or Iterable."); } return new GivenUUIDGenerator(ImmutableList.copyOf(uuids)); }
protected JsonObjectLocation contextLeft(Object o) { return checkPresent(leftObj.getLocations().getLocationOf(o), "can't find left context for " + o); }
@Override public Given load(Map given) { String path = given.containsKey("path") ? checkInstanceOf("path", given.get("path"), String.class) : "data://"; String data; if (given.containsKey("data")) { data = checkInstanceOf("data", given.get("data"), String.class); } else if (given.containsKey("path")) { if (path.startsWith("/")) { checkInstanceOf("collection", given.get("collection"), String.class), path, data,
protected JsonObjectLocation contextLeft(Object o) { return checkPresent(leftObj.getLocations().getLocationOf(o), "can't find left context for " + o); }
@Override public Given load(Map given) { String path = given.containsKey("path") ? checkInstanceOf("path", given.get("path"), String.class) : "data://"; String data; if (given.containsKey("data")) { data = checkInstanceOf("data", given.get("data"), String.class); } else if (given.containsKey("path")) { if (path.startsWith("/")) { checkInstanceOf("collection", given.get("collection"), String.class), path, data,
protected JsonObjectLocation contextRight(Object o) { return checkPresent(rightObj.getLocations().getLocationOf(o), "can't find right context for " + o); }
List<Given> givens = loadGivens(spec); List<WhenHttpRequest> whens = Lists.newArrayList(); Iterable wts = checkInstanceOf("wts", spec.get("wts"), Iterable.class); for (Object wt : wts) { Map whenThen = checkInstanceOf("when/then", wt, Map.class); Object w = whenThen.get("when"); if (w instanceof String) { String then = checkInstanceOf("then", whenThen.get("then"), String.class).trim(); HttpStatus code = HttpStatus.OK; int endLineIndex = then.indexOf("\n"); return new RestxSpec(path, checkInstanceOf("title", spec.get("title"), String.class), ImmutableList.copyOf(givens), ImmutableList.copyOf(whens));
/** * Builds a component by class. * * This is a shortcut for queryByClass(cls).mandatory().findOneAsComponent().get() * * Therefore it raises an exception if no component of this class is found or if several one match. * * @param componentClass * @param <T> * @return */ public <T> T getComponent(Class<T> componentClass) { return checkPresent(queryByClass(componentClass).mandatory().findOneAsComponent(), "component of class %s not found", componentClass); }
List<Given> givens = loadGivens(spec); List<WhenHttpRequest> whens = Lists.newArrayList(); Iterable wts = checkInstanceOf("wts", spec.get("wts"), Iterable.class); for (Object wt : wts) { Map whenThen = checkInstanceOf("when/then", wt, Map.class); Object w = whenThen.get("when"); if (w instanceof String) { String then = checkInstanceOf("then", whenThen.get("then"), String.class).trim(); HttpStatus code = HttpStatus.OK; int endLineIndex = then.indexOf("\n"); return new RestxSpec(path, checkInstanceOf("title", spec.get("title"), String.class), ImmutableList.copyOf(givens), ImmutableList.copyOf(whens));
/** * Builds a component by name. * * This is a shortcut for queryByName(name).mandatory().findOneAsComponent().get() * * Therefore it raises an exception if no component of this name is found. * * @param componentName * @param <T> * @return */ public <T> T getComponent(Name<T> componentName) { return checkPresent(queryByName(componentName).mandatory().findOneAsComponent(), "component of name %s not found", componentName); }