ReportExporter { public void export(Object object, boolean applicationPrefix, String namePrefix, Map<String, String> tags) { ReportedBean reportedBean = ReportedBean.forTarget(object, bucketIdProvider); if (!reportedBean.getAttributes().isEmpty()) { try { registry.register(object, reportedBean, applicationPrefix, namePrefix, tags); } catch (InstanceAlreadyExistsException e) { throw new ReportException(Reason.INSTANCE_ALREADY_EXISTS, e.getMessage()); } } } @Inject  ReportExporter(ReportedBeanRegistry registry, BucketIdProvider bucketIdProvider); void export(Object object, boolean applicationPrefix, String namePrefix, Map<String, String> tags); void unexportObject(Object object); @Deprecated void export(String name, Object object); @Deprecated void export(ObjectName objectName, Object object); @Deprecated void unexport(String name); @Deprecated void unexport(ObjectName objectName);  }
@Test public void testExport() { reportExporter.export(TESTING_OBJECT, false, "TestingObject", ImmutableMap.of()); assertExported(false, ImmutableMap.of()); }
@Test public void testExportPrefix() { reportExporter.export(TESTING_OBJECT, true, "TestingObject", ImmutableMap.of("foo", "bar")); assertExported(true, ImmutableMap.of("foo", "bar")); }
@Test public void testExportNoAttributes() { reportExporter.export(new Object(), false, "TestingObject", ImmutableMap.of()); assertEquals(registry.getReportedBeans(), ImmutableList.of()); }
@Test public void testExportDuplicate() { try { reportExporter.export(TESTING_OBJECT, false, "TestingObject", ImmutableMap.of()); reportExporter.export(TESTING_OBJECT, false, "TestingObject", ImmutableMap.of()); fail("expected ReportException"); } catch (ReportException e) { assertEquals(e.getReason(), Reason.INSTANCE_ALREADY_EXISTS); assertEquals(e.getMessage(), "Testing Object is already registered"); } }
@Test public void testNotifyBucketIdProvider() { TestingBucketed bucketed = spy(new TestingBucketed()); reportExporter.export(bucketed, false, "TestingBucketed", ImmutableMap.of()); verify(bucketed).setBucketIdProvider(bucketIdProvider); verify(bucketed.getInnerBucketed()).setBucketIdProvider(bucketIdProvider); }
@Test public void testLegacyExportString() { reportExporter.export(TESTING_OBJECT_NAME.getCanonicalName(), TESTING_OBJECT); assertExported(false, ImmutableMap.of()); }
@Test public void testLegacyExportStringNoAttributes() { reportExporter.export(TESTING_OBJECT_NAME.getCanonicalName(), new Object()); assertEquals(registry.getReportedBeans(), ImmutableList.of()); }
@Test public void testLegacyExportStringMalformedName() { try { reportExporter.export("TestingObject", TESTING_OBJECT); fail("expected ReportException"); } catch (ReportException e) { assertEquals(e.getReason(), Reason.MALFORMED_OBJECT_NAME); assertEquals(e.getMessage(), "Key properties cannot be empty"); } }
@Test public void testLegacyExportStringDuplicate() { try { reportExporter.export(TESTING_OBJECT_NAME.getCanonicalName(), TESTING_OBJECT); reportExporter.export(TESTING_OBJECT_NAME.getCanonicalName(), TESTING_OBJECT); fail("expected ReportException"); } catch (ReportException e) { assertEquals(e.getReason(), Reason.INSTANCE_ALREADY_EXISTS); assertEquals(e.getMessage(), "com.proofpoint.reporting:name=TestingObject is already registered"); } }
@Test public void testLegacyExportObjectName() { reportExporter.export(TESTING_OBJECT_NAME, TESTING_OBJECT); assertExported(false, ImmutableMap.of()); }
@Test public void testLegacyExportObjectNameNoAttributes() { reportExporter.export(TESTING_OBJECT_NAME, new Object()); assertEquals(registry.getReportedBeans(), ImmutableList.of()); }
@Test public void testLegacyExportObjectNameDuplicate() { try { reportExporter.export(TESTING_OBJECT_NAME, TESTING_OBJECT); reportExporter.export(TESTING_OBJECT_NAME, TESTING_OBJECT); fail("expected ReportException"); } catch (ReportException e) { assertEquals(e.getReason(), Reason.INSTANCE_ALREADY_EXISTS); assertEquals(e.getMessage(), "com.proofpoint.reporting:name=TestingObject is already registered"); } }
@Test public void testLegacyNotifyBucketIdProvider() { TestingBucketed bucketed = spy(new TestingBucketed()); reportExporter.export(TESTING_OBJECT_NAME, bucketed); verify(bucketed).setBucketIdProvider(bucketIdProvider); verify(bucketed.getInnerBucketed()).setBucketIdProvider(bucketIdProvider); }