Search in sources :

Example 41 with Action

use of ddf.action.Action in project ddf by codice.

the class DerivedContentActionProviderTest method testGetActionsNonContentUriWithQualifier.

@Test
public void testGetActionsNonContentUriWithQualifier() throws Exception {
    ActionImpl expectedAction = new ActionImpl("expected", "expected", "expected", actionUri.toURL());
    when(mockResourceActionProvider.getAction(any(Metacard.class))).thenReturn(expectedAction);
    when(attribute.getValues()).thenReturn(Arrays.asList(actionUri));
    List<Action> actions = actionProvider.getActions(metacard);
    assertThat(actions, hasSize(1));
    assertThat(actions.get(0), notNullValue());
    assertThat(actions.get(0).getUrl(), notNullValue());
    assertThat(actions.get(0).getUrl().toString(), is(actionUri.toString()));
    assertThat(actions.get(0).getTitle(), is("View " + QUALIFIER_VALUE));
}
Also used : Metacard(ddf.catalog.data.Metacard) Action(ddf.action.Action) ActionImpl(ddf.action.impl.ActionImpl) Test(org.junit.Test)

Example 42 with Action

use of ddf.action.Action in project ddf by codice.

the class AtomTransformer method addLink.

// a Link object could not be made and returned without a classpath problem in the OSGi runtime
// therefore this was a workaround that did not require me to add special logic for
// contextclassloader
private void addLink(ActionProvider actionProvider, Metacard metacard, Entry entry, String linkType) {
    if (actionProvider != null) {
        try {
            Action action = actionProvider.getAction(metacard);
            if (action != null) {
                if (actionProvider.equals(resourceActionProvider) && metacard.getResourceURI() != null) {
                    Link viewLink = addLinkHelper(action, entry, linkType, MIME_TYPE_OCTET_STREAM);
                    try {
                        Long length = Long.parseLong(metacard.getResourceSize(), 10);
                        viewLink.setLength(length);
                    } catch (NumberFormatException e) {
                        LOGGER.debug("Could not cast {} as Long type.", metacard.getResourceSize());
                    }
                } else if (actionProvider.equals(thumbnailActionProvider) && metacard.getThumbnail() != null) {
                    addLinkHelper(action, entry, linkType, MIME_TYPE_JPEG);
                } else if (!actionProvider.equals(resourceActionProvider) && !actionProvider.equals(thumbnailActionProvider)) {
                    addLinkHelper(action, entry, linkType, MIME_TYPE_OCTET_STREAM);
                }
            }
        } catch (RuntimeException e) {
            // ActionProvider is injected but not available
            LOGGER.debug("Could not retrieve action.", e);
        }
    }
}
Also used : Action(ddf.action.Action) Link(org.apache.abdera.model.Link)

Example 43 with Action

use of ddf.action.Action in project ddf by codice.

the class IdpLogoutActionProviderTest method testGetAction.

@Test
public void testGetAction() throws Exception {
    Subject subject = mock(Subject.class);
    HashMap map = new HashMap();
    map.put("idp", subject);
    Action action = idpLogoutActionProvider.getAction(map);
    Assert.assertTrue("Expected the encrypted nameId and time", action.getUrl().getQuery().contains(nameIdTime));
}
Also used : Action(ddf.action.Action) HashMap(java.util.HashMap) Subject(org.apache.shiro.subject.Subject) Test(org.junit.Test)

Example 44 with Action

use of ddf.action.Action in project ddf by codice.

the class IdpLogoutActionProviderTest method testGetActionFailure.

@Test
public void testGetActionFailure() throws Exception {
    Object notsubject = new Object();
    HashMap map = new HashMap();
    map.put("idp", notsubject);
    when(encryptionService.encrypt(any(String.class))).thenReturn(nameIdTime);
    Action action = idpLogoutActionProvider.getAction(map);
    Assert.assertNull("Expected the url to be null", action.getUrl());
}
Also used : Action(ddf.action.Action) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

Action (ddf.action.Action)44 Test (org.junit.Test)33 URL (java.net.URL)9 HashMap (java.util.HashMap)8 Metacard (ddf.catalog.data.Metacard)7 ActionProvider (ddf.action.ActionProvider)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 ActionImpl (ddf.action.impl.ActionImpl)3 MultiActionProvider (ddf.action.MultiActionProvider)2 BinaryContent (ddf.catalog.data.BinaryContent)2 Result (ddf.catalog.data.Result)2 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)2 ResultImpl (ddf.catalog.data.impl.ResultImpl)2 SourceResponse (ddf.catalog.operation.SourceResponse)2 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Date (java.util.Date)2