ProtocolExtension a = new ProtocolExtension(); ProtocolExtension b = new ProtocolExtension(); checkEquals(a, b); ticketKeys.add("FIRST"); ticketKeys.add("SECOND"); a.setTicketKeys(ticketKeys); checkEquals(a.getTicketKeys(), ticketKeys); checkNotEquals(a, b); b.setTicketKeys(new ArrayList<String>()); checkNotEquals(a, b); b.setTicketKeys(ticketKeys); checkEquals(a, b); a.setDevMake("a1"); checkNotEquals(a, b); b.setDevMake("b1"); checkNotEquals(a, b); b.setDevMake("a1"); checkEquals(a, b); a.setDevModel("a2"); checkNotEquals(a, b); b.setDevModel("b2"); checkNotEquals(a, b); b.setDevModel("a2"); checkEquals(a, b);
@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 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; }
@Override public void read(JSONObject object) throws JSONException { setTicketKeys(JSONUtils.readStringArray(object, TICKET_KEYS)); setDevMake(object.optString(DEV_MAKE, null)); setDevModel(object.optString(DEV_MODEL, null)); }
ProtocolExtension protocol = new ProtocolExtension(); Extensions ext = new Extensions(); ext.setProtocol(protocol); assertEquals(Collections.singletonList(authenticationProvider.getTicketKeyHash()), protocol.getTicketKeys());
dest.getExt().setProtocol(new ProtocolExtension()); dest.getExt().getProtocol().setDevModel(device.getModel()); dest.getExt().getProtocol().setDevMake(device.getOemName());
@Test public void compareDifferentType() { TestUtils.compareSelfNullClass(new ProtocolExtension()); }
ProtocolExtension protocol = new ProtocolExtension(); protocol.setDevModel("model"); a.setProtocol(protocol); checkNotEquals(a, b); b.setProtocol(new ProtocolExtension()); checkNotEquals(a, b); b.setProtocol(a.getProtocol());
ProtocolExtension protocol = new ProtocolExtension(); protocol.read(object.getJSONObject(PROTOCOL)); setProtocol(protocol);
List<String> ticketKeys = ((CommonSchemaLog) log).getExt().getProtocol().getTicketKeys(); if (ticketKeys != null) { for (String ticketKey : ticketKeys) {
assertNotNull(commonSchemaLog.getExt()); assertNotNull(commonSchemaLog.getExt().getProtocol()); assertEquals("model", commonSchemaLog.getExt().getProtocol().getDevModel()); assertEquals("oemName", commonSchemaLog.getExt().getProtocol().getDevMake()); assertNotNull(commonSchemaLog.getExt().getUser()); assertEquals("c:alice", commonSchemaLog.getExt().getUser().getLocalId());
/** * Add ticket to common schema logs. */ private static void addTicketToLog(@NonNull Log log) { /* Decorate only common schema logs when an authentication provider was registered. */ if (sAuthenticationProvider != null && log instanceof CommonSchemaLog) { /* Add ticket reference to log. */ CommonSchemaLog csLog = (CommonSchemaLog) log; String ticketKey = sAuthenticationProvider.getTicketKeyHash(); csLog.getExt().getProtocol().setTicketKeys(Collections.singletonList(ticketKey)); /* * Check if we should try to refresh token if soon expired. * Known corner case: if already expired and refresh takes longer than batching log time, * then next logs will be anonymous until token refreshed. */ sAuthenticationProvider.checkTokenExpiry(); } }
@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; } }
final ProtocolExtension protocol = new ProtocolExtension(); log.setExt(new Extensions() {{ setProtocol(protocol); assertEquals(Collections.singletonList(authenticationProvider.getTicketKeyHash()), protocol.getTicketKeys());
@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());
assertEquals(Collections.singletonList(authenticationProvider1.getTicketKeyHash()), sentLogs.get(0).getExt().getProtocol().getTicketKeys()); assertEquals(Collections.singletonList(authenticationProvider2.getTicketKeyHash()), sentLogs.get(1).getExt().getProtocol().getTicketKeys());
log.getExt().setProtocol(new ProtocolExtension()); checkSerialization(serializer, log); log.getExt().getProtocol().setTicketKeys(Arrays.asList("First", "Second")); checkSerialization(serializer, log); log.getExt().getProtocol().setDevMake("Samsung"); checkSerialization(serializer, log); log.getExt().getProtocol().setDevModel("S5"); checkSerialization(serializer, log);
setProtocol(new ProtocolExtension()); }}; final CommonSchemaLog log1 = mock(CommonSchemaLog.class);
setProtocol(new ProtocolExtension()); }}); LogContainer container = new LogContainer() {{
}}; Extensions ext2 = new Extensions() {{ setProtocol(new ProtocolExtension()); }}; when(log1.getExt()).thenReturn(ext1);