/** * Convenience method for creating a list of objects. * * @param t The initial values. * @return A new list. */ @SafeVarargs public static <T> AList<T> create(T...t) { return new AList<T>().appendAll(t); }
/** * Convenience method for creating a list of objects. * * @param t The initial values. * @return A new list. */ @SafeVarargs public static <T> AList<T> create(T...t) { return new AList<T>().appendAll(t); }
/** * Convenience method for creating a list of objects. * * @param t The initial values. * @return A new list. */ @SafeVarargs public static <T> AList<T> create(T...t) { return new AList<T>().appendAll(t); }
/** * Adds a query data entry to this request. * * @param key The query key. * @param value The query value. * <br>The value is converted to a simple string using {@link Object#toString()}. * @return This object (for method chaining). */ public MockServletRequest query(String key, Object value) { if (queryData == null) queryData = new LinkedHashMap<>(); String s = asString(value); String[] existing = queryData.get(key); if (existing == null) existing = new String[]{s}; else existing = new AList<>().appendAll(Arrays.asList(existing)).append(s).toArray(new String[0]); queryData.put(key, existing); return this; }
/** * Adds a form data entry to this request. * * @param key The form data key. * @param value The form data value. * <br>The value is converted to a simple string using {@link Object#toString()}. * @return This object (for method chaining). */ public MockServletRequest formData(String key, Object value) { if (formDataMap == null) formDataMap = new LinkedHashMap<>(); String s = asString(value); String[] existing = formDataMap.get(key); if (existing == null) existing = new String[]{s}; else existing = new AList<>().appendAll(Arrays.asList(existing)).append(s).toArray(new String[0]); formDataMap.put(key, existing); return this; }
/** * Adds a query data entry to this request. * * @param key The query key. * @param value The query value. * <br>The value is converted to a simple string using {@link Object#toString()}. * @return This object (for method chaining). */ public MockServletRequest query(String key, Object value) { if (queryData == null) queryData = new LinkedHashMap<>(); String s = asString(value); String[] existing = queryData.get(key); if (existing == null) existing = new String[]{s}; else existing = new AList<>().appendAll(Arrays.asList(existing)).append(s).toArray(new String[0]); queryData.put(key, existing); return this; }
/** * Adds a form data entry to this request. * * @param key The form data key. * @param value The form data value. * <br>The value is converted to a simple string using {@link Object#toString()}. * @return This object (for method chaining). */ public MockServletRequest formData(String key, Object value) { if (formDataMap == null) formDataMap = new LinkedHashMap<>(); String s = asString(value); String[] existing = formDataMap.get(key); if (existing == null) existing = new String[]{s}; else existing = new AList<>().appendAll(Arrays.asList(existing)).append(s).toArray(new String[0]); formDataMap.put(key, existing); return this; }
/** * Adds a query data entry to this request. * * @param key The query key. * @param value The query value. * <br>The value is converted to a simple string using {@link Object#toString()}. * @return This object (for method chaining). */ public MockServletRequest query(String key, Object value) { if (queryData == null) queryData = new LinkedHashMap<>(); String s = asString(value); String[] existing = queryData.get(key); if (existing == null) existing = new String[]{s}; else existing = new AList<>().appendAll(Arrays.asList(existing)).append(s).toArray(new String[0]); queryData.put(key, existing); return this; }
/** * Adds a form data entry to this request. * * @param key The form data key. * @param value The form data value. * <br>The value is converted to a simple string using {@link Object#toString()}. * @return This object (for method chaining). */ public MockServletRequest formData(String key, Object value) { if (formDataMap == null) formDataMap = new LinkedHashMap<>(); String s = asString(value); String[] existing = formDataMap.get(key); if (existing == null) existing = new String[]{s}; else existing = new AList<>().appendAll(Arrays.asList(existing)).append(s).toArray(new String[0]); formDataMap.put(key, existing); return this; }
@Test public void testAssertTypes() throws Exception { assertTypes(new AList<>().appendAll(1,2,3), Integer.class); assertTypes(new AList<>().appendAll(1,2,3), Object.class); assertTypes(new AList<>().appendAll(String.class), String.class); assertTypes(new AList<>().appendAll(String.class), CharSequence.class); assertTypes(new AList<>().appendAll(1,2,3), Long.class); } catch (Exception e) { assertEquals("Invalid list entry '1' (Integer). Not one of the following types: ['java.lang.Long']", e.getMessage()); assertTypes(new AList<>().appendAll(1,2,3), String.class); } catch (Exception e) { assertEquals("Invalid list entry '1' (Integer). Not one of the following types: ['java.lang.String']", e.getMessage()); assertTypes(new AList<>().appendAll(String.class), StringBuilder.class); } catch (Exception e) { assertEquals("Invalid list entry ''java.lang.String'' (Class). Not one of the following types: ['java.lang.StringBuilder']", e.getMessage()); assertTypes(new AList<>().appendAll(CharSequence.class), String.class); } catch (Exception e) { assertEquals("Invalid list entry ''java.lang.CharSequence'' (Class). Not one of the following types: ['java.lang.String']", e.getMessage());
@Test public void testListStringHash() throws Exception { PropertyStoreBuilder b1 = PropertyStore.create(), b2 = PropertyStore.create(); PropertyStore ps = null; b1.set("A.f1.ls", new AList<String>().appendAll("foo", "bar")); b2.set("A.f1.ls", new String[]{"foo","bar"}); testEquals(b1, b2); b2.set("A.f1.ls", new AList<>().appendAll(new StringBuilder("foo"), new StringBuilder("bar"))); testEquals(b1, b2); b2.set("A.f1.ls", new AList<>().appendAll(new StringBuilder("bar"), new StringBuilder("foo"))); testNotEquals(b1, b2); b2.set("A.f1.ls", new Object[]{new StringBuilder("foo"), new StringBuilder("bar")}); testEquals(b1, b2); b2.set("A.f1.ls", new Object[]{new StringBuilder("foo"), new StringBuilder("bar")}); testEquals(b1, b2); b1.set("A.f1.ls", new String[]{"foo"}); b2.set("A.f1.ls", new String[]{"foox"}); testNotEquals(b1, b2); ps = b1.build(); b1.set("A.f1.ls", "['foo']"); assertTrue(ps == b1.build()); b1.set("A.f1.ls", "['bar']"); assertTrue(ps != b1.build()); b1.clear(); b2.clear(); testEquals(b1, b2); }
@Test public void testSetStringHash() throws Exception { PropertyStoreBuilder b1 = PropertyStore.create(), b2 = PropertyStore.create(); PropertyStore ps = null; b1.set("A.f1.ss", new AList<String>().appendAll("foo", "bar")); b2.set("A.f1.ss", new String[]{"foo","bar"}); testEquals(b1, b2); b2.set("A.f1.ss", new AList<>().appendAll(new StringBuilder("bar"), new StringBuilder("foo"))); testEquals(b1, b2); b2.set("A.f1.ss", new Object[]{new StringBuilder("bar"), new StringBuilder("foo")}); testEquals(b1, b2); b1.set("A.f1.ss", new String[]{"foo"}); b2.set("A.f1.ss", new String[]{"foox"}); testNotEquals(b1, b2); ps = b1.build(); b1.set("A.f1.ss", "['foo']"); assertTrue(ps == b1.build()); b1.set("A.f1.ss", "['bar']"); assertTrue(ps != b1.build()); b1.clear(); b2.clear(); testEquals(b1, b2); }
@Test public void testSetIntegerHash() throws Exception { PropertyStoreBuilder b1 = PropertyStore.create(), b2 = PropertyStore.create(); PropertyStore ps = null; b1.set("A.f1.si", new AList<String>().appendAll("1", "2")); b2.set("A.f1.si", new String[]{"1","2"}); testEquals(b1, b2); b2.set("A.f1.si", new AList<>().appendAll(new StringBuilder("2"), 1)); testEquals(b1, b2); b2.set("A.f1.si", new Object[]{new StringBuilder("2"), 1}); testEquals(b1, b2); b1.set("A.f1.si", new String[]{"1"}); b2.set("A.f1.si", new String[]{"2"}); testNotEquals(b1, b2); ps = b1.build(); b1.set("A.f1.si", "['1']"); assertTrue(ps == b1.build()); b1.set("A.f1.si", "['2']"); assertTrue(ps != b1.build()); b1.clear(); b2.clear(); testEquals(b1, b2); }
@Test public void testListObjectHash() throws Exception { PropertyStoreBuilder b1 = PropertyStore.create(), b2 = PropertyStore.create(); PropertyStore ps = null; b1.set("A.f1.lo", new AList<>().appendAll("foo", 123, true, TestEnum.ONE)); b2.set("A.f1.lo", new AList<>().appendAll("foo", 123, true, TestEnum.ONE)); testEquals(b1, b2); b2.set("A.f1.lo", new AList<>().appendAll(123, true, TestEnum.ONE, "foo")); testNotEquals(b1, b2); b2.set("A.f1.lo", new Object[]{"foo", 123, true, TestEnum.ONE}); testEquals(b1, b2); b1.set("A.f1.lo", new Object[]{StringBuilder.class}); b2.set("A.f1.lo", new Object[]{StringBuffer.class}); testNotEquals(b1, b2); b1.set("A.f1.lo", "foo"); ps = b1.build(); b1.set("A.f1.lo", "foo"); assertTrue(ps == b1.build()); b1.set("A.f1.lo", "bar"); assertTrue(ps != b1.build()); b1.clear(); b2.clear(); testEquals(b1, b2); }
@Test public void testListIntegerHash() throws Exception { PropertyStoreBuilder b1 = PropertyStore.create(), b2 = PropertyStore.create(); PropertyStore ps = null; b1.set("A.f1.li", new AList<String>().appendAll("1", "2")); b2.set("A.f1.li", new String[]{"1","2"}); testEquals(b1, b2); b2.set("A.f1.li", new String[]{"2","1"}); testNotEquals(b1, b2); b2.set("A.f1.li", new int[]{1,2}); testEquals(b1, b2); b2.set("A.f1.li", new AList<>().appendAll(new StringBuilder("2"), 1)); testNotEquals(b1, b2); b2.set("A.f1.li", new Object[]{new StringBuilder("1"), 2}); testEquals(b1, b2); b1.set("A.f1.li", new String[]{"1"}); b2.set("A.f1.li", new String[]{"2"}); testNotEquals(b1, b2); ps = b1.build(); b1.set("A.f1.li", "['1']"); assertTrue(ps == b1.build()); b1.set("A.f1.li", "['2']"); assertTrue(ps != b1.build()); b1.clear(); b2.clear(); testEquals(b1, b2); }
@Test public void testSetClassHash() throws Exception { PropertyStoreBuilder b1 = PropertyStore.create(), b2 = PropertyStore.create(); PropertyStore ps = null; b1.set("A.f1.sc", new AList<Class<?>>().appendAll(String.class, Integer.class)); b2.set("A.f1.sc", new Class<?>[]{Integer.class,String.class}); testEquals(b1, b2); b2.set("A.f1.sc", new AList<>().appendAll(Integer.class, String.class)); testEquals(b1, b2); b2.set("A.f1.sc", new Object[]{String.class, Integer.class}); testEquals(b1, b2); b1.set("A.f1.sc", new Class[]{String.class}); b2.set("A.f1.sc", new Class[]{Integer.class}); testNotEquals(b1, b2); ps = b1.build(); b1.set("A.f1.sc", String.class); assertTrue(ps == b1.build()); b1.set("A.f1.sc", Map.class); assertTrue(ps != b1.build()); b1.clear(); b2.clear(); testEquals(b1, b2); }
@Test public void testListClassHash() throws Exception { PropertyStoreBuilder b1 = PropertyStore.create(), b2 = PropertyStore.create(); PropertyStore ps = null; b1.set("A.f1.lc", new AList<Class<?>>().appendAll(String.class, Integer.class)); b2.set("A.f1.lc", new Class<?>[]{String.class,Integer.class}); testEquals(b1, b2); b2.set("A.f1.lc", new Class<?>[]{Integer.class,String.class}); testNotEquals(b1, b2); b2.set("A.f1.lc", new AList<>().appendAll(String.class, Integer.class)); testEquals(b1, b2); b2.set("A.f1.lc", new Object[]{String.class, Integer.class}); testEquals(b1, b2); b1.set("A.f1.lc", new Class[]{String.class}); b2.set("A.f1.lc", new Class[]{Integer.class}); testNotEquals(b1, b2); ps = b1.build(); b1.set("A.f1.lc", String.class); assertTrue(ps == b1.build()); b1.set("A.f1.lc", Map.class); assertTrue(ps != b1.build()); b1.clear(); b2.clear(); testEquals(b1, b2); }
@Test public void testPlainTextParams() throws Exception { WriterSerializer s = UrlEncodingSerializer.DEFAULT.builder().paramFormatPlain().build(); assertEquals("_value=foo", s.serialize("foo")); assertEquals("_value='foo'", s.serialize("'foo'")); assertEquals("_value=(foo)", s.serialize("(foo)")); assertEquals("_value=@(foo)", s.serialize("@(foo)")); Map<String,Object> m = new AMap<String,Object>() .append("foo", "foo") .append("'foo'", "'foo'") .append("(foo)", "(foo)") .append("@(foo)", "@(foo)"); assertEquals("foo=foo&'foo'='foo'&(foo)=(foo)&@(foo)=@(foo)", s.serialize(m)); List<String> l = new AList<String>().appendAll("foo", "'foo'", "(foo)", "@(foo)"); assertEquals("0=foo&1='foo'&2=(foo)&3=@(foo)", s.serialize(l)); A a = new A(); assertEquals("'foo'='foo'&(foo)=(foo)&@(foo)=@(foo)&foo=foo", s.serialize(a)); }