Example usage for org.apache.commons.lang.builder ToStringBuilder reflectionToString

List of usage examples for org.apache.commons.lang.builder ToStringBuilder reflectionToString

Introduction

In this page you can find the example usage for org.apache.commons.lang.builder ToStringBuilder reflectionToString.

Prototype

public static String reflectionToString(Object object) 

Source Link

Document

Forwards to ReflectionToStringBuilder.

Usage

From source file:org.codice.ddf.endpoints.rest.TestRestEndpoint.java

@Test()
public void testAddDocumentPositiveCase() throws IOException, CatalogTransformerException, IngestException,
        SourceUnavailableException, URISyntaxException {

    CatalogFramework framework = givenCatalogFramework(SAMPLE_ID);

    HttpHeaders headers = createHeaders(Arrays.asList(MediaType.APPLICATION_JSON));

    RESTEndpoint rest = new RESTEndpoint(framework);

    addMatchingService(rest, Arrays.asList(getSimpleTransformer()));

    UriInfo info = givenUriInfo(SAMPLE_ID);

    Response response = rest.addDocument(headers, info, mock(HttpServletRequest.class),
            mock(MultipartBody.class), new ByteArrayInputStream("".getBytes()));

    LOGGER.debug(ToStringBuilder.reflectionToString(response));

    assertThat(response.getStatus(), equalTo(201));

    assertThat(response.getMetadata(), notNullValue());

    assertThat(response.getMetadata().get(Metacard.ID).get(0).toString(), equalTo(SAMPLE_ID));
}

From source file:org.codice.ddf.rest.impl.CatalogServiceImplTest.java

@Test
public void testAddDocumentPositiveCase() throws Exception {

    CatalogFramework framework = givenCatalogFramework();

    HttpHeaders headers = createHeaders(Collections.singletonList(MediaType.APPLICATION_JSON));

    CatalogServiceImpl catalogService = new CatalogServiceImpl(framework, attachmentParser, attributeRegistry);

    addMatchingService(catalogService, Collections.singletonList(getSimpleTransformer()));

    String response = catalogService.addDocument(headers.getRequestHeader(HttpHeaders.CONTENT_TYPE),
            mock(MultipartBody.class), null, new ByteArrayInputStream("".getBytes()));

    LOGGER.debug(ToStringBuilder.reflectionToString(response));

    assertThat(response, equalTo(SAMPLE_ID));
}

From source file:org.codice.ddf.rest.impl.CatalogServiceImplTest.java

@Test
@SuppressWarnings({ "unchecked" })
public void testAddDocumentWithAttributeOverrides() throws Exception {

    CatalogFramework framework = givenCatalogFramework();

    AttributeDescriptor descriptor = new AttributeDescriptorImpl("custom.attribute", true, true, false, false,
            BasicTypes.STRING_TYPE);// ww  w  .  j  a  v  a  2  s.c o  m

    HttpHeaders headers = createHeaders(Collections.singletonList(MediaType.APPLICATION_JSON));
    BundleContext bundleContext = mock(BundleContext.class);
    Collection<ServiceReference<InputTransformer>> serviceReferences = new ArrayList<>();
    ServiceReference serviceReference = mock(ServiceReference.class);
    InputTransformer inputTransformer = mock(InputTransformer.class);
    when(inputTransformer.transform(any())).thenReturn(new MetacardImpl());
    when(bundleContext.getService(serviceReference)).thenReturn(inputTransformer);
    serviceReferences.add(serviceReference);
    when(bundleContext.getServiceReferences(InputTransformer.class, "(id=xml)")).thenReturn(serviceReferences);

    when(attributeRegistry.lookup("custom.attribute")).thenReturn(Optional.of(descriptor));

    CatalogServiceImpl catalogService = new CatalogServiceImpl(framework, attachmentParser, attributeRegistry) {
        @Override
        BundleContext getBundleContext() {
            return bundleContext;
        }
    };

    UuidGenerator uuidGenerator = mock(UuidGenerator.class);
    when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
    catalogService.setUuidGenerator(uuidGenerator);

    addMatchingService(catalogService, Collections.singletonList(getSimpleTransformer()));

    List<Attachment> attachments = new ArrayList<>();
    ContentDisposition contentDisposition = new ContentDisposition(
            "form-data; name=parse.resource; filename=C:\\DDF\\metacard.txt");
    Attachment attachment = new Attachment("parse.resource", new ByteArrayInputStream("Some Text".getBytes()),
            contentDisposition);
    attachments.add(attachment);
    ContentDisposition contentDisposition2 = new ContentDisposition("form-data; name=custom.attribute; ");
    Attachment attachment2 = new Attachment(descriptor.getName(),
            new ByteArrayInputStream("CustomValue".getBytes()), contentDisposition2);
    attachments.add(attachment2);
    MultipartBody multipartBody = new MultipartBody(attachments);

    String response = catalogService.addDocument(headers.getRequestHeader(HttpHeaders.CONTENT_TYPE),
            multipartBody, null, new ByteArrayInputStream("".getBytes()));

    LOGGER.debug(ToStringBuilder.reflectionToString(response));

    ArgumentCaptor<CreateStorageRequest> captor = new ArgumentCaptor<>();
    verify(framework, times(1)).create(captor.capture());
    assertThat(captor.getValue().getContentItems().get(0).getMetacard().getMetacardType()
            .getAttributeDescriptor(descriptor.getName()), equalTo(descriptor));
}

From source file:org.codice.ddf.rest.impl.CatalogServiceImplTest.java

@Test
@SuppressWarnings({ "unchecked" })
public void testAddDocumentWithMetadataPositiveCase() throws Exception {

    CatalogFramework framework = givenCatalogFramework();

    HttpHeaders headers = createHeaders(Collections.singletonList(MediaType.APPLICATION_JSON));
    BundleContext bundleContext = mock(BundleContext.class);
    Collection<ServiceReference<InputTransformer>> serviceReferences = new ArrayList<>();
    ServiceReference serviceReference = mock(ServiceReference.class);
    InputTransformer inputTransformer = mock(InputTransformer.class);
    when(inputTransformer.transform(any())).thenReturn(new MetacardImpl());
    when(bundleContext.getService(serviceReference)).thenReturn(inputTransformer);
    serviceReferences.add(serviceReference);
    when(bundleContext.getServiceReferences(InputTransformer.class, "(id=xml)")).thenReturn(serviceReferences);

    CatalogServiceImpl catalogService = new CatalogServiceImpl(framework, attachmentParser, attributeRegistry) {
        @Override/*  w w w  .jav  a2  s.  c  om*/
        BundleContext getBundleContext() {
            return bundleContext;
        }
    };

    UuidGenerator uuidGenerator = mock(UuidGenerator.class);
    when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
    catalogService.setUuidGenerator(uuidGenerator);

    when(attributeRegistry.lookup(Core.METADATA))
            .thenReturn(Optional.of(new CoreAttributes().getAttributeDescriptor(Core.METADATA)));

    addMatchingService(catalogService, Collections.singletonList(getSimpleTransformer()));

    List<Attachment> attachments = new ArrayList<>();
    ContentDisposition contentDisposition = new ContentDisposition(
            "form-data; name=parse.resource; filename=C:\\DDF\\metacard.txt");
    Attachment attachment = new Attachment("parse.resource", new ByteArrayInputStream("Some Text".getBytes()),
            contentDisposition);
    attachments.add(attachment);
    ContentDisposition contentDisposition1 = new ContentDisposition(
            "form-data; name=parse.metadata; filename=C:\\DDF\\metacard.xml");
    Attachment attachment1 = new Attachment("parse.metadata",
            new ByteArrayInputStream("Some Text Again".getBytes()), contentDisposition1);
    attachments.add(attachment1);
    ContentDisposition contentDisposition2 = new ContentDisposition(
            "form-data; name=metadata; filename=C:\\DDF\\metacard.xml");
    Attachment attachment2 = new Attachment("metadata",
            new ByteArrayInputStream("<meta>beta</meta>".getBytes()), contentDisposition2);
    attachments.add(attachment2);
    MultipartBody multipartBody = new MultipartBody(attachments);

    String response = catalogService.addDocument(headers.getRequestHeader(HttpHeaders.CONTENT_TYPE),
            multipartBody, null, new ByteArrayInputStream("".getBytes()));

    LOGGER.debug(ToStringBuilder.reflectionToString(response));

    assertThat(response, equalTo(SAMPLE_ID));
}

From source file:org.gbif.portal.dao.geospatial.impl.hibernate.CountryDAOImpl.java

/**
 * Retrieves the locale using the default if the supplied locale is null or not
 * supported./*from w ww .j  a v a  2  s  .c o  m*/
 * 
 * @param locale
 * @return language code e.g. "en"
 */
@SuppressWarnings("unchecked")
protected String getLocaleForQuery(Locale locale) {
    if (supportedLocales == null) {
        logger.debug("retrieving supported locales");
        supportedLocales = (List<String>) getHibernateTemplate().execute(new HibernateCallback() {

            public Object doInHibernate(final Session session) {
                // initialise supported locales
                final Query query = session.createQuery("select distinct cn.locale from CountryName cn");
                return query.list();
            }
        });
        if (logger.isDebugEnabled())
            logger.debug("Supported locales: " + ToStringBuilder.reflectionToString(supportedLocales));
    }
    if (locale != null) {
        if (supportedLocales.contains(locale.getLanguage()))
            return locale.getLanguage();
    }
    return defaultISOLanguageCode;
}

From source file:org.glite.security.voms.admin.operations.attributes.CreateAttributeDescriptionOperation.java

protected String logArgs() {

    return ToStringBuilder.reflectionToString(this);

}

From source file:org.glite.security.voms.admin.operations.BaseVomsOperation.java

protected final void logRequiredPermissions() {

    __log.debug("[" + this.getClass() + "] requiredPerms: "
            + ToStringBuilder.reflectionToString(__requiredPermissions) + "");
}

From source file:org.glite.security.voms.admin.operations.BaseVomsOperation.java

protected String logArgs() {

    String message = ToStringBuilder.reflectionToString(this);

    // FIXME: really a quick n' dirty trick to build these LOG messages...:(
    message = message.replaceAll(",?__\\p{Alpha}*=[^,\\]]*,?", "");
    return message;
}

From source file:org.glite.security.voms.admin.operations.groups.CreateGroupOperation.java

protected String logArgs() {

    return ToStringBuilder.reflectionToString(this);
}

From source file:org.glite.security.voms.admin.operations.VOMSPermissionList.java

public String toString() {

    return ToStringBuilder.reflectionToString(this);
}