@Test public void timestampLabelSetWithMissingAttributeThrowsError() { thrown.expect(RuntimeException.class); thrown.expectMessage("PubSub message is missing a value for timestamp label myLabel"); Map<String, String> map = ImmutableMap.of("otherLabel", "whatever"); PubsubClient.extractTimestamp("myLabel", null, map); }
@Test public void timestampLabelParsesMillisecondsSinceEpoch() { long time = 1446162101123L; Map<String, String> map = ImmutableMap.of("myLabel", String.valueOf(time)); long timestamp = PubsubClient.extractTimestamp("myLabel", null, map); assertEquals(time, timestamp); }
@Test public void noTimestampLabelAndInvalidPubsubPublishThrowsError() { thrown.expect(NumberFormatException.class); PubsubClient.extractTimestamp(null, "not-a-date", null); }
@Test public void timestampLabelWithNullAttributesThrowsError() { thrown.expect(RuntimeException.class); thrown.expectMessage("PubSub message is missing a value for timestamp label myLabel"); PubsubClient.extractTimestamp("myLabel", null, null); }
@Test public void noTimestampLabelReturnsPubsubPublish() { final long time = 987654321L; long timestamp = PubsubClient.extractTimestamp(null, String.valueOf(time), null); assertEquals(time, timestamp); }
private long parse(String timestamp) { Map<String, String> map = ImmutableMap.of("myLabel", timestamp); return PubsubClient.extractTimestamp("myLabel", null, map); }
@Test public void topicPathFromNameWellFormed() { TopicPath path = PubsubClient.topicPathFromName("test", "something"); assertEquals("projects/test/topics/something", path.getPath()); assertEquals("/topics/test/something", path.getV1Beta1Path()); }
@Test public void subscriptionPathFromNameWellFormed() { SubscriptionPath path = PubsubClient.subscriptionPathFromName("test", "something"); assertEquals("projects/test/subscriptions/something", path.getPath()); assertEquals("/subscriptions/test/something", path.getV1Beta1Path()); }
@Test public void projectPathFromIdWellFormed() { ProjectPath path = PubsubClient.projectPathFromId("test"); assertEquals("projects/test", path.getPath()); }