Tabnine Logo
JsonMap
Code IndexAdd Tabnine to your IDE (free)

How to use
JsonMap
in
de.otto.edison.testsupport.util

Best Java code snippets using de.otto.edison.testsupport.util.JsonMap (Showing top 20 results out of 315)

origin: otto-de/edison-microservice

public Object getObject(final String key) {
  if (jsonObject == null) {
    throw new NullPointerException("json object is null");
  }
  if (is(Map.class)) {
    return get(key);
  } else {
    throw new IllegalArgumentException("not a map but a " + jsonObject.getClass().getSimpleName());
  }
}
origin: otto-de/edison-microservice

public Instant getInstant(final String key) {
  if (jsonObject == null) {
    throw new NullPointerException("json object is null");
  }
  if (is(Map.class)) {
    final String value = getString(key);
    return value != null ? parse(value) : null;
  } else {
    throw new IllegalArgumentException("not a map but a " + jsonObject.getClass().getSimpleName());
  }
}
origin: otto-de/edison-microservice

public boolean getBoolean(final String key, final boolean defaultValue) {
  final Boolean result = getBoolean(key);
  return result != null ? result : defaultValue;
}
origin: otto-de/edison-microservice

public JsonMap get(final String s) {
  if (jsonObject == null) {
    throw new NullPointerException("json object is null");
  }
  if (is(Map.class)) {
    String[] segments = s.split("\\.");
    if (segments.length < 2) {
      final Object object = ((Map) jsonObject).get(s);
      return object != null ? new JsonMap(object) : null;
    } else {
      return get(segments[0]).get(s.substring(s.indexOf(".")+1));
    }
  } else {
    throw new IllegalArgumentException("not a map but a " + jsonObject.getClass().getSimpleName());
  }
}
origin: otto-de/edison-microservice

@Test
public void shouldGetNullForMissingString() {
  final Map<String, ?> map = singletonMap("key", null);
  assertThat(jsonMapFrom(map).getString("key"), is(nullValue()));
  assertThat(jsonMapFrom(map).getString("doesnotexist"), is(nullValue()));
}
origin: otto-de/edison-microservice

@Test
public void shouldCreateStatusRepresentationWithDetailInclUrl() {
  // given
  final StatusRepresentation json = statusRepresentationOf(
      applicationStatus(
          mock(ApplicationInfo.class),
          mock(ClusterInfo.class),
          mock(SystemInfo.class),
          mock(VersionInfo.class),
          mock(TeamInfo.class),
          singletonList(
              statusDetail("someDetail", OK, "some message", link("item", "http://example.org/some/url", "some title"))
          )
      )
  );
  // then
  assertThat(json.application.status, is(OK));
  final JsonMap jsonMap = jsonMapFrom(json.application.statusDetails.get("someDetail"));
  final JsonMap link = jsonMap.get("links").asListOf(JsonMap.class).get(0);
  assertThat(link.getString("href"), is("http://example.org/some/url"));
  assertThat(link.getString("title"), is("some title"));
  assertThat(link.getString("rel"), is("item"));
}
origin: otto-de/edison-microservice

@Test
public void shouldGetInnerValueByDottedKeys() {
  /**
   * {
   * "outer" : {
   *      "innter": {
   *          "key" : "value"
   *      }
   * }
   */
  final Map<String, ?> inner = singletonMap("key", "value");
  final Map<String, ?> map = singletonMap("outer", singletonMap("inner", inner));
  assertThat(jsonMapFrom(map).get("outer.inner").getString("key"), is("value"));
}
origin: otto-de/edison-microservice

@Test
public void shouldGetLongFromString() {
  final Map<String, ?> map = singletonMap("key", "1");
  assertThat(jsonMapFrom(map).getLong("key"), is(1L));
}
origin: otto-de/edison-microservice

@Test
public void shouldFallbackOnDefaultInt() {
  final JsonMap empty = jsonMapFrom(new HashMap<String, Object>());
  assertThat(empty.getInt("key", 1), is(1));
}
origin: otto-de/edison-microservice

@Test
public void shouldFallbackOnDefaultBoolean() {
  final JsonMap empty = jsonMapFrom(new HashMap<String, Object>());
  assertThat(empty.getBoolean("key", TRUE), is(TRUE));
}
origin: otto-de/edison-microservice

@Test
public void shouldGetDouble() {
  final Map<String, ?> map = singletonMap("key", 2.0);
  assertThat(jsonMapFrom(map).getDouble("key"), is(2.0));
}
origin: otto-de/edison-microservice

@Test
public void shouldRemoveKeyFromInnerObject() {
  final Map<String, ?> map = singletonMap("key", new HashMap<String, String>() {{
    put("removeMe", "hello world");
  }});
  final JsonMap jsonMap = jsonMapFrom(map);
  jsonMap.get("key").remove("removeMe");
  assertThat(jsonMap, is(jsonMapFrom(singletonMap("key", emptyMap()))));
}
origin: otto-de/edison-microservice

public Date getDate(final String key) {
  if (jsonObject == null) {
    throw new NullPointerException("json object is null");
  }
  if (is(Map.class)) {
    final JsonMap value = get(key);
    if (value == null) {
      return null;
    } else {
      if (value.is(Date.class)) {
        return (Date) value.jsonObject;
      } if (value.is(String.class)) {
        return from(parse(value.toString()));
      } else {
        throw new ClassCastException("Value of " + key + " is not a date but a " + value.getClass().getSimpleName());
      }
    }
  } else {
    throw new IllegalArgumentException("not a map but a " + jsonObject.getClass().getSimpleName());
  }
}
origin: otto-de/edison-microservice

@Test
public void shouldGetInnerMap() {
  final Map<String, ?> inner = singletonMap("key", "value");
  final Map<String, ?> map = singletonMap("inner", inner);
  assertThat(jsonMapFrom(map).get("inner"), is(jsonMapFrom(inner)));
}
origin: otto-de/edison-microservice

@Test
public void shouldGetDate() {
  final Date date = new Date();
  final Map<String, ?> map = singletonMap("key", date);
  assertThat(jsonMapFrom(map).getDate("key"), is(date));
}
origin: otto-de/edison-microservice

@Test
public void shouldReturnNullIfInstantValueIsNotPresentAndNoDefaultSpecified() {
  final JsonMap empty = jsonMapFrom(new HashMap<String, Object>());
  assertThat(empty.getInstant("key"), is(nullValue()));
}
origin: otto-de/edison-microservice

public String getString(final String key, final String defaultValue) {
  final String result = getString(key);
  return result != null ? result : defaultValue;
}
origin: otto-de/edison-microservice

@Test
public void shouldRemoveKeyFromTopLevel() {
  final Map<String, ?> map = new HashMap<String, String>() {{
    put("removeMe", "hello world");
  }};
  final JsonMap jsonMap = jsonMapFrom(map);
  jsonMap.remove("removeMe");
  assertThat(jsonMap, is(jsonMapFrom(emptyMap())));
}
origin: otto-de/edison-microservice

public Integer getInt(final String key, final Integer defaultValue) {
  final Integer result = getInt(key);
  return result != null ? result : defaultValue;
}
origin: otto-de/edison-microservice

public long getLong(final String key, final long defaultValue) {
  final Long result = getLong(key);
  return result != null ? result : defaultValue;
}
de.otto.edison.testsupport.utilJsonMap

Most used methods

  • get
  • getString
  • getBoolean
  • getDouble
  • getInt
  • getLong
  • jsonMapFrom
  • <init>
  • asListOf
  • getDate
  • getFloat
  • getInstant
  • getFloat,
  • getInstant,
  • is,
  • remove,
  • toString

Popular in Java

  • Creating JSON documents from java classes using gson
  • setContentView (Activity)
  • startActivity (Activity)
  • putExtra (Intent)
  • PrintWriter (java.io)
    Wraps either an existing OutputStream or an existing Writerand provides convenience methods for prin
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • JTextField (javax.swing)
  • Base64 (org.apache.commons.codec.binary)
    Provides Base64 encoding and decoding as defined by RFC 2045.This class implements section 6.8. Base
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now