SoapCallFactory { @SuppressWarnings("unchecked") public OMElement createCall(String sessionId, String methodPath, Object arg) { OMElement method = fac.createOMElement(CORE_CALL, mag); method.declareNamespace(soapEnc); method.declareNamespace(soapXml); method.declareNamespace(xsi); method.declareNamespace(xsd); OMElement paramSession = fac.createOMElement(SESSION_ID, noNs); paramSession.addChild(fac.createOMText(paramSession, sessionId)); method.addChild(paramSession); OMElement resourcePath = fac.createOMElement(RESOURCE_PATH, noNs); resourcePath.addChild(fac.createOMText(resourcePath, methodPath)); method.addChild(resourcePath); OMElement paramArgs; if (arg instanceof Iterable) { Iterable<Object> args = (Iterable<Object>) arg; paramArgs = fac.createOMElement(ARGUMENTS, noNs); paramArgs.addAttribute("arrayType", xsd.getPrefix() + ":ur-type[" + Iterables.size(args) + "]", soapEnc); paramArgs.addAttribute("type", soapEnc.getPrefix() + ":Array", xsi); for (Object argument : args) { paramArgs.addChild(typedElement(noNs, "item", argument)); } } else if (arg instanceof Map) { Map<String, Object> args = (Map<String, Object>) arg; paramArgs = typedElement(noNs, ARGUMENTS, arg); paramArgs.addAttribute("arrayType", xsd.getPrefix() + ":Map[" + args.size() + "]", soapEnc); paramArgs.addAttribute("type", soapEnc.getPrefix() + ":Array", xsi); } else if (arg != null && (arg.getClass().isArray() || arg.getClass().getName().equals("sun.org.mozilla.javascript.internal.NativeArray"))) { Object[] args = (Object[]) arg; paramArgs = fac.createOMElement(ARGUMENTS, noNs); paramArgs.addAttribute("arrayType", xsd.getPrefix() + ":ur-type[" + args.length + "]", soapEnc); paramArgs.addAttribute("type", soapEnc.getPrefix() + ":Array", xsi); for (Object argument : args) { paramArgs.addChild(typedElement(noNs, "item", argument)); } } else { paramArgs = typedElement(noNs, ARGUMENTS, arg); } method.addChild(paramArgs); return method; } SoapCallFactory(OMMetaFactory omMetaFactory);  SoapCallFactory(); OMElement createLoginCall(String user, String password); OMElement createLogoutCall(String sessionId); @SuppressWarnings("unchecked") OMElement createCall(String sessionId, String methodPath, Object arg);  }
@Test public void createCallList() { List<Serializable> args = ImmutableList.of(2, ImmutableMap.of("name", "Bandana", "description", "Bandana keren untuk penampilan Anda")); OMElement element = soapCallFactory.createCall("abc", "catalog_category.create", args); log.info("createCallList {}", element); assertNotNull(element); assertEquals(3, Iterators.size(element.getChildElements())); }
@Test public void createCallArray() { Serializable[] args = new Serializable[] { 2, ImmutableMap.of("name", "Bandana", "description", "Bandana keren untuk penampilan Anda") }; OMElement element = soapCallFactory.createCall("abc", "catalog_category.create", args); log.info("createCallArray {}", element); assertNotNull(element); assertEquals(3, Iterators.size(element.getChildElements())); }
@Test public void createCallJavascriptArray() throws ScriptException { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine scriptEngine = manager.getEngineByName("js"); Object args = scriptEngine.eval("[ 2, {'name': 'Bandana', 'description': 'Bandana keren untuk penampilan Anda'} ]"); OMElement element = soapCallFactory.createCall("abc", "catalog_category.create", args); log.info("createCallJavascriptArray {}", element); assertNotNull(element); assertEquals(3, Iterators.size(element.getChildElements())); }
@Test public void createCallJavascriptIntArray() throws ScriptException { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine scriptEngine = manager.getEngineByName("js"); Object args = scriptEngine.eval("[ 2, 5, 9 ]"); OMElement element = soapCallFactory.createCall("abc", "catalog_category.create", args); log.info("createCallJavascriptIntArray {}", element); assertNotNull(element); assertEquals(3, Iterators.size(element.getChildElements())); }
@Test @Ignore("Assertion failing") public void createCallProductUpdatePrice() throws ScriptException { ImmutableList<ProductUpdatePrice> products = ImmutableList.of(new ProductUpdatePrice("ajah_a", new BigDecimal(500000), new BigDecimal(600000)), new ProductUpdatePrice("zibalabel_b_06", new BigDecimal(500000), new BigDecimal(600000))); OMElement element = soapCallFactory.createCall("abc", ResourcePath.ProductUpdatePrice.getPath(), new Object[] { products }); log.info("createCallProductUpdatePrice {}", element); assertNotNull(element); assertEquals(1, Iterators.size(element.getChildElements())); }