@Override public int hashCode() { int result = metadata != null ? metadata.hashCode() : 0; result = 31 * result + (protocol != null ? protocol.hashCode() : 0); result = 31 * result + (user != null ? user.hashCode() : 0); result = 31 * result + (device != null ? device.hashCode() : 0); result = 31 * result + (os != null ? os.hashCode() : 0); result = 31 * result + (app != null ? app.hashCode() : 0); result = 31 * result + (net != null ? net.hashCode() : 0); result = 31 * result + (sdk != null ? sdk.hashCode() : 0); result = 31 * result + (loc != null ? loc.hashCode() : 0); return result; } }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Extensions that = (Extensions) o; if (metadata != null ? !metadata.equals(that.metadata) : that.metadata != null) return false; if (protocol != null ? !protocol.equals(that.protocol) : that.protocol != null) return false; if (user != null ? !user.equals(that.user) : that.user != null) return false; if (device != null ? !device.equals(that.device) : that.device != null) return false; if (os != null ? !os.equals(that.os) : that.os != null) return false; if (app != null ? !app.equals(that.app) : that.app != null) return false; if (net != null ? !net.equals(that.net) : that.net != null) return false; if (sdk != null ? !sdk.equals(that.sdk) : that.sdk != null) return false; return loc != null ? loc.equals(that.loc) : that.loc == null; }
@Test public void invalidBaseDataRemovesBaseType() { MockCommonSchemaLog log = new MockCommonSchemaLog(); log.setExt(new Extensions()); List<TypedProperty> properties = new ArrayList<>(); properties.add(typedProperty("baseType", "Some.Type")); properties.add(typedProperty("baseData", "value")); CommonSchemaDataUtils.addCommonSchemaData(properties, log); /* Check everything removed. */ assertEquals(0, log.getData().getProperties().length()); assertNull(log.getExt().getMetadata()); }
@Test() public void filterInvalidProperties() throws JSONException { MockCommonSchemaLog log = new MockCommonSchemaLog(); List<TypedProperty> properties = new ArrayList<>(); properties.add(typedProperty("a", "b")); properties.add(typedProperty(null, "c")); properties.add(typedProperty("d", null)); CommonSchemaDataUtils.addCommonSchemaData(properties, log); assertEquals(1, log.getData().getProperties().length()); assertEquals("b", log.getData().getProperties().getString("a")); assertNull(log.getExt()); }
@Override public Object answer(InvocationOnMock invocation) { ProtocolExtension protocol = new ProtocolExtension(); Extensions ext = new Extensions(); ext.setProtocol(protocol); CommonSchemaLog log = new CommonSchemaEventLog(); log.setExt(ext); sentLogs.add(log); /* Call the listener after conversion of common schema for authentication decoration. */ AnalyticsTransmissionTarget.getChannelListener().onPreparingLog(log, "test"); return null; } }).when(mChannel).enqueue(any(Log.class), anyString(), anyInt());
@Test public void checkPartAConversionDoesNotInstantiateExtensionObjectAgain() { Log log = mock(Log.class); when(log.getDevice()).thenReturn(getDevice(0)); MockCommonSchemaLog commonSchemaLog = new MockCommonSchemaLog(); Extensions extensions = new Extensions(); commonSchemaLog.setExt(extensions); PartAUtils.addPartAFromLog(log, commonSchemaLog, "T1UUID1-T2UUID2"); assertEquals(extensions, commonSchemaLog.getExt()); }
private static void testValidName(String name) { CommonSchemaLog log = new MockCommonSchemaLog(); PartAUtils.setName(log, name); assertEquals(name, log.getName()); }
@Override public void write(JSONStringer writer) throws JSONException { JSONUtils.writeStringArray(writer, TICKET_KEYS, getTicketKeys()); JSONUtils.write(writer, DEV_MAKE, getDevMake()); JSONUtils.write(writer, DEV_MODEL, getDevModel()); }
@Override public Log create() { return new MockCommonSchemaLog(); } }
@Test public void setInvalidNames() { testInvalidName(null); testInvalidName("a b"); testInvalidName("abc"); testInvalidName("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789a"); testInvalidName("...."); testInvalidName("a..b"); testInvalidName("a.b."); testInvalidName(".a.b"); }
@Test public void setValidNames() { testValidName("AbCd"); testValidName("a.b.c"); testValidName("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"); testValidName("A_._"); }
@Test public void baseTypeOverriddenToBeInvalid() { MockCommonSchemaLog log = new MockCommonSchemaLog(); log.setExt(new Extensions()); List<TypedProperty> properties = new ArrayList<>(); properties.add(typedProperty("baseType", "Some.Type")); properties.add(typedProperty("baseType.something", "test")); properties.add(typedProperty("baseData.something", "test")); CommonSchemaDataUtils.addCommonSchemaData(properties, log); /* Check only string base type was kept. */ assertEquals(2, log.getData().getProperties().length()); assertEquals("Some.Type", log.getData().getProperties().optString("baseType")); assertNull(log.getExt().getMetadata()); } }
@Test public void emptyStringsAreAllowed() throws JSONException { MockCommonSchemaLog log = new MockCommonSchemaLog(); List<TypedProperty> properties = new ArrayList<>(); properties.add(typedProperty("", "")); CommonSchemaDataUtils.addCommonSchemaData(properties, log); assertEquals(1, log.getData().getProperties().length()); assertEquals("", log.getData().getProperties().getString("")); assertNull(log.getExt()); }
private static void testInvalidName(String name) { CommonSchemaLog log = new MockCommonSchemaLog(); try { PartAUtils.setName(log, name); fail("Expected exception"); } catch (IllegalArgumentException e) { assertNull(log.getName()); } }
@Test public void emptyProperties() { MockCommonSchemaLog log = new MockCommonSchemaLog(); CommonSchemaDataUtils.addCommonSchemaData(Collections.<TypedProperty>emptyList(), log); assertEquals(0, log.getData().getProperties().length()); assertNull(log.getExt()); }
@Test public void overrideProperty() { MockCommonSchemaLog log = new MockCommonSchemaLog(); List<TypedProperty> properties = new ArrayList<>(); properties.add(typedProperty("a.b", "1")); properties.add(typedProperty("a.b.c.d", "2")); properties.add(typedProperty("a.b.c", "3")); CommonSchemaDataUtils.addCommonSchemaData(properties, log); JSONObject b = log.getData().getProperties().optJSONObject("a").optJSONObject("b"); assertNotNull(b); assertEquals("3", b.optString("c", null)); assertNull(log.getExt()); }
@Test public void nullProperties() { MockCommonSchemaLog log = new MockCommonSchemaLog(); CommonSchemaDataUtils.addCommonSchemaData(null, log); assertNull(log.getData()); assertNull(log.getExt()); }