Search in sources :

Example 51 with XMLEncoder

use of java.beans.XMLEncoder in project ddf by codice.

the class SolrProviderExtensibleMetacards method queryInteger.

@Test
public void queryInteger() throws UnsupportedQueryException {
    Query query = new QueryImpl(getFilterBuilder().attribute(intField).greaterThan().number(intFieldValue - 1));
    QueryRequest request = new QueryRequestImpl(query);
    SourceResponse response = provider.query(request);
    assertEquals(1, response.getResults().size());
    Metacard resultMetacard = response.getResults().get(0).getMetacard();
    assertThat(resultMetacard.getAttribute(Metacard.ID), notNullValue());
    assertThat(resultMetacard.getAttribute(doubleField).getValue(), equalTo(doubleFieldValue));
    assertThat(resultMetacard.getAttribute(intField).getValue(), equalTo(intFieldValue));
    assertThat(resultMetacard.getAttribute(floatField).getValue(), equalTo(floatFieldValue));
    assertThat(resultMetacard.getAttribute(longField).getValue(), equalTo(longFieldValue));
    assertThat(resultMetacard.getAttribute(byteField).getValue(), equalTo(byteFieldValue));
    assertThat(resultMetacard.getAttribute(booleanField).getValue(), equalTo(true));
    assertThat(resultMetacard.getAttribute(dateField).getValue(), equalTo(dateFieldValue));
    assertThat(resultMetacard.getAttribute(geoField).getValue(), equalTo(geoFieldValue));
    assertThat(resultMetacard.getAttribute(shortField).getValue(), equalTo(shortFieldValue));
    assertThat(resultMetacard.getAttribute(objectField).getValue(), instanceOf(BevelBorder.class));
    /*
     * Going to use the XMLEncoder. If it writes out the objects the same way in xml, then they
     * are the same.
     */
    ByteArrayOutputStream beveledBytesStreamFromSolr = new ByteArrayOutputStream();
    XMLEncoder solrXMLEncoder = new XMLEncoder(new BufferedOutputStream(beveledBytesStreamFromSolr));
    solrXMLEncoder.writeObject((resultMetacard.getAttribute(objectField).getValue()));
    solrXMLEncoder.close();
    ByteArrayOutputStream beveledBytesStreamOriginal = new ByteArrayOutputStream();
    XMLEncoder currendEncoder = new XMLEncoder(new BufferedOutputStream(beveledBytesStreamOriginal));
    currendEncoder.writeObject(objectFieldValue);
    currendEncoder.close();
    assertThat(beveledBytesStreamFromSolr.toByteArray(), equalTo(beveledBytesStreamOriginal.toByteArray()));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Metacard(ddf.catalog.data.Metacard) XMLEncoder(java.beans.XMLEncoder) Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) BevelBorder(javax.swing.border.BevelBorder) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) SolrProviderTest(ddf.catalog.source.solr.SolrProviderTest) Test(org.junit.Test)

Aggregations

XMLEncoder (java.beans.XMLEncoder)51 ByteArrayOutputStream (java.io.ByteArrayOutputStream)21 BufferedOutputStream (java.io.BufferedOutputStream)19 FileOutputStream (java.io.FileOutputStream)14 IOException (java.io.IOException)13 XMLDecoder (java.beans.XMLDecoder)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 Test (org.junit.Test)9 File (java.io.File)8 LinkedList (java.util.LinkedList)7 FileInputStream (java.io.FileInputStream)6 AssertionFailedError (junit.framework.AssertionFailedError)6 ExceptionListener (java.beans.ExceptionListener)5 PersistenceDelegate (java.beans.PersistenceDelegate)4 BufferedInputStream (java.io.BufferedInputStream)4 DefaultPersistenceDelegate (java.beans.DefaultPersistenceDelegate)3 Encoder (java.beans.Encoder)3 OutputStream (java.io.OutputStream)3 Metacard (ddf.catalog.data.Metacard)2 Query (ddf.catalog.operation.Query)2