Example usage for java.util List getClass

List of usage examples for java.util List getClass

Introduction

In this page you can find the example usage for java.util List getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.eclipse.emf.teneo.hibernate.mapping.elist.HibernatePersistableEList.java

/** Overridden because general list type is not supported as a replacement */
@Override/*from  w w w.  jav  a  2  s  .  com*/
public void replaceDelegate(List<E> newDelegate) {
    if (newDelegate instanceof PersistentList) {
        // disabled this assertion because in case of a session refresh it
        // is possible
        // that the list is replaced by a persistent list
        // AssertUtil.assertTrue("This elist " + logString + " contains a
        // different list than the " +
        // " passed list",
        // ((PersistentList)newDelegate).isWrapper(delegate));
        super.replaceDelegate(newDelegate);
    } else if (newDelegate instanceof PersistentBag) {
        // disabled this assertion because in case of a session refresh it
        // is possible
        // that the list is replaced by a persistent list
        // AssertUtil.assertTrue("This elist " + logString + " contains a
        // different list than the " +
        // " passed list",
        // ((PersistentBag)newDelegate).isWrapper(delegate));
        super.replaceDelegate(newDelegate);
    } else if (newDelegate instanceof PersistentIdentifierBag) {
        // Added to support <idbag>
        super.replaceDelegate(newDelegate);
    } else if (newDelegate == delegate) // this can occur and is okay, do
    // nothing in this case
    {

    } else {
        throw new HbMapperException("Type " + newDelegate.getClass().getName() + " can not be "
                + " used as a replacement for elist " + logString);
    }
}

From source file:com.qingstor.sdk.utils.QSJSONUtil.java

private static void setParameterToMap(Method m, Object source, Field f, Object data) {
    if (data != null) {
        try {//from   w  w w .  ja  v a2s  . c o m
            if (data instanceof JSONArray || data instanceof JSONObject) {
                Class fClass = f.getType();
                if (fClass.equals(List.class)) {
                    List invokeData = new ArrayList();
                    ParameterizedType stringListType = (ParameterizedType) f.getGenericType();
                    Class<?> cls = (Class<?>) stringListType.getActualTypeArguments()[0];

                    if (cls.equals(String.class) || cls.equals(Integer.class) || cls.equals(Double.class)
                            || cls.equals(Long.class) || cls.equals(Float.class)) {
                        if (data instanceof JSONArray) {
                            JSONArray jsonData = (JSONArray) data;
                            for (int i = 0; i < jsonData.length(); i++) {

                                Object o = toObject(jsonData, i);
                                invokeData.add(o);
                            }
                        }
                    } else {
                        if (data instanceof JSONArray) {
                            JSONArray jsonData = (JSONArray) data;
                            for (int i = 0; i < jsonData.length(); i++) {
                                Object fObject = cls.newInstance();
                                JSONObject o = toJSONObject(jsonData, i);
                                Class tmpClass = fObject.getClass();
                                while (tmpClass != Object.class) {
                                    Field[] fields = tmpClass.getDeclaredFields();
                                    initParameter(o, fields, tmpClass, fObject);
                                    tmpClass = tmpClass.getSuperclass();
                                }
                                invokeData.add(fObject);
                            }
                        }
                    }

                    m.invoke(source, invokeData);

                } else if (fClass.equals(Map.class)) {
                    Map invokeData = new HashMap();
                    if (data instanceof JSONObject) {
                        JSONObject jsonData = (JSONObject) data;
                        for (int i = 0; i < jsonData.length(); i++) {
                            String key = toJSONObject(jsonData, i) + "";
                            Object value = toJSONObject(jsonData, key);
                            invokeData.put(key, value);
                        }
                    }
                    m.invoke(source, invokeData);
                } else {

                    Object invokeData = f.getType().newInstance();
                    Class tmpClass = invokeData.getClass();
                    while (tmpClass != Object.class) {
                        Field[] fields = tmpClass.getDeclaredFields();
                        initParameter((JSONObject) data, fields, tmpClass, invokeData);
                        tmpClass = tmpClass.getSuperclass();
                    }
                    m.invoke(source, invokeData);
                }

            } else {
                if (f.getType().equals(data.getClass())) {
                    m.invoke(source, data);
                } else {
                    m.invoke(source, getParseValue(f.getType(), data));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:org.itracker.web.forms.IssueForm.java

/**
 * Run provided BEANSHELL script against form instance, taking into account
 * incoming event type, field raised an event and current values.
 * As a result, a set of new current values is returned and if
 * appropriate, default values are changed in form.
 * TODO: should issue, project, user, services be available too?
 *
 * @param projectScript is a script to run.
 * @param event         is an event type.
 * @param currentValue  the current field value
 * @param optionValues  is a set of valid option-values.
 * @param currentErrors is a container for occured errors.
 * @return new changed currentValue.//from  w  ww  .java  2 s  . c om
 */
public String processFieldScript(ProjectScript projectScript, int event, String currentValue,
        List<NameValuePair> optionValues, ActionMessages currentErrors) throws WorkflowException {
    if (projectScript == null) {
        throw new WorkflowException("ProjectScript was null.", WorkflowException.INVALID_ARGS);
    }
    if (currentErrors == null) {
        throw new WorkflowException("Errors was null.", WorkflowException.INVALID_ARGS);
    }

    if (!isWorkflowScriptsAllowed()) {
        return currentValue;
    }

    String result = currentValue;

    try {
        if (projectScript.getScript().getLanguage() != WorkflowScript.ScriptLanguage.Groovy) {
            result = processBeanShellScript(projectScript, currentValue, optionValues, currentErrors, event);
        } else {
            result = processGroovyScript(projectScript, currentValue, optionValues, currentErrors, event);
        }
        if (log.isDebugEnabled()) {
            log.debug("processFieldScript: Script returned current value of '" + optionValues + "' ("
                    + (optionValues != null ? optionValues.getClass().getName() : "NULL") + ")");
        }
    } catch (EvalError evalError) {
        log.error("processFieldScript: eval failed: " + projectScript, evalError);
        currentErrors.add(ActionMessages.GLOBAL_MESSAGE,
                new ActionMessage("itracker.web.error.invalidscriptdata", evalError.getMessage()));
    } catch (RuntimeException e) {
        log.warn("processFieldScript: Error processing field script: " + projectScript, e);
        currentErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system.message",
                new Object[] { e.getMessage(), ITrackerResources.getString("itracker.web.attr.script") // Script
                }));
    }
    if (log.isDebugEnabled()) {
        log.debug("processFieldScript: returning " + result + ", errors: " + currentErrors);
    }
    return result;
}

From source file:ddf.catalog.impl.CatalogFrameworkImplTest.java

/**
 * Tests that multiple ResourceReaders with the same scheme will be invoked if the first one did
 * not return a Response.//w w  w .  j a va  2s .  c o m
 *
 * @throws Exception
 */
@Test
@Ignore //CACHE
public void testGetResourceToTestSecondResourceReaderWithSameSchemeGetsCalledIfFirstDoesNotReturnAnything()
        throws Exception {
    String localProviderName = "ddf";
    String metacardId = "123";
    final String EXPECTED = "result from mockResourceResponse2";
    final String DDF = "ddf";

    // Mock a Catalog Provider
    CatalogProvider provider = mock(CatalogProvider.class);
    when(provider.getId()).thenReturn(localProviderName);
    when(provider.isAvailable(isA(SourceMonitor.class))).thenReturn(true);
    when(provider.isAvailable()).thenReturn(true);

    // Mock register the provider in the container
    // Mock the source poller
    SourcePoller mockPoller = mock(SourcePoller.class);
    when(mockPoller.getCachedSource(isA(Source.class))).thenReturn(null);

    // Create two ResourceReaders. The first should not return anything
    // and the second should.
    ResourceReader resourceReader1 = mock(ResourceReader.class);
    ResourceReader resourceReader2 = mock(ResourceReader.class);

    // Set the supported Schemes so that both ResourceReaders use
    // the same scheme ("DAD")
    Set<String> supportedSchemes = new HashSet<String>();
    supportedSchemes.add("DAD");

    when(resourceReader1.getSupportedSchemes()).thenReturn(supportedSchemes);
    when(resourceReader2.getSupportedSchemes()).thenReturn(supportedSchemes);

    List<ResourceReader> resourceReaders = new ArrayList<ResourceReader>();
    resourceReaders.add(resourceReader1);
    resourceReaders.add(resourceReader2);

    // Set up the requests and responses. The first ResourceReader will return null
    // and the second one will retrieve a value, showing that if more than one
    // ResourceReader with the same scheme are used, they will be called until a
    // response is returned
    ResourceRequest mockResourceRequest = mock(ResourceRequest.class);
    URI myURI = new URI("DAD", "host", "/path", "fragment");
    when(mockResourceRequest.getAttributeValue()).thenReturn(myURI);
    when(mockResourceRequest.getAttributeName())
            .thenReturn(new String(ResourceRequest.GET_RESOURCE_BY_PRODUCT_URI));

    Result result = mock(Result.class);
    Metacard metacard = mock(Metacard.class);
    when(metacard.getResourceURI()).thenReturn(myURI);
    when(result.getMetacard()).thenReturn(metacard);
    List<Result> results = new ArrayList<Result>();
    results.add(result);

    QueryResponse queryResponse = mock(QueryResponse.class);
    when(queryResponse.getResults()).thenReturn(results);

    List<Source> federatedSources = new ArrayList<Source>();

    FederationStrategy strategy = mock(FederationStrategy.class);
    when(strategy.federate(isA(federatedSources.getClass()), isA(QueryRequest.class)))
            .thenReturn(queryResponse);

    ResourceResponse mockResourceResponse1 = mock(ResourceResponse.class);
    when(mockResourceResponse1.getRequest()).thenReturn(mockResourceRequest);
    when(mockResourceResponse1.getResource()).thenReturn(null);
    when(resourceReader1.retrieveResource(any(URI.class), anyMap())).thenReturn(null);

    Resource mockResource = mock(Resource.class);
    when(mockResource.getName()).thenReturn(EXPECTED);
    ResourceResponse mockResourceResponse2 = mock(ResourceResponse.class);
    when(mockResourceResponse2.getResource()).thenReturn(mockResource);
    when(resourceReader2.retrieveResource(any(URI.class), anyMap())).thenReturn(mockResourceResponse2);

    FrameworkProperties frameworkProperties = new FrameworkProperties();
    frameworkProperties.setSourcePoller(mockPoller);
    frameworkProperties.setResourceReaders(resourceReaders);
    frameworkProperties.setFederationStrategy(strategy);
    frameworkProperties.setCatalogProviders(Collections.singletonList(provider));

    CatalogFrameworkImpl framework = new CatalogFrameworkImpl(frameworkProperties);
    framework.bind(provider);
    framework.setId(DDF);

    ResourceResponse response = framework.getResource(mockResourceRequest, false, DDF);

    // Verify that the Response is as expected
    org.junit.Assert.assertEquals(EXPECTED, response.getResource().getName());

    // Verify that resourceReader1 was called 1 time
    // This line is equivalent to verify(resourceReader1,
    // times(1)).retrieveResource(any(URI.class), anyMap());
    verify(resourceReader1).retrieveResource(any(URI.class), anyMap());

}

From source file:ddf.catalog.CatalogFrameworkImplTest.java

/**
 * Tests that you can get a resource's (product) options. Covers the case where the source ID
 * specified is actually the local catalog provider's site name (so this reduces down to a
 * getResourceOptions for local provider); and the case where a federated source is specified.
 * //from  w ww .  j av  a 2  s.com
 * Test for DDF-1763.
 * 
 * @throws Exception
 */
@Test
public void testGetResourceOptions() throws Exception {
    String localProviderName = "ddf";
    String federatedSite1Name = "fed-site-1";
    String metacardId = "123";

    // The resource's URI
    URI metacardUri = new URI(
            "http:///27+Nov+12+12%3A30%3A04?MyPhotograph%0Ahttp%3A%2F%2F172.18.14.53%3A8080%2Fabc%2Fimages%2FActionable.jpg%0AMyAttachment%0Ahttp%3A%2F%2F172.18.14.53%3A8080%2Fabc#abc.xyz.dao.URLResourceOptionDataAccessObject");

    Set<String> supportedOptions = new HashSet<String>();
    supportedOptions.add("MyPhotograph");
    supportedOptions.add("MyAttachment");

    // Catalog Provider
    CatalogProvider provider = mock(CatalogProvider.class);
    when(provider.getId()).thenReturn(localProviderName);
    when(provider.isAvailable(isA(SourceMonitor.class))).thenReturn(true);
    when(provider.isAvailable()).thenReturn(true);

    // Federated Source 1
    FederatedSource federatedSource1 = mock(FederatedSource.class);
    when(federatedSource1.getId()).thenReturn(federatedSite1Name);
    when(federatedSource1.isAvailable(isA(SourceMonitor.class))).thenReturn(true);
    when(federatedSource1.isAvailable()).thenReturn(true);
    when(federatedSource1.getOptions(isA(Metacard.class))).thenReturn(supportedOptions);

    List<FederatedSource> federatedSources = new ArrayList<FederatedSource>();
    federatedSources.add(federatedSource1);

    // Mock register the provider in the container
    // Mock the source poller
    SourcePoller mockPoller = mock(SourcePoller.class);
    when(mockPoller.isAvailable(isA(Source.class))).thenReturn(Boolean.TRUE);

    Metacard metacard = mock(Metacard.class);
    when(metacard.getId()).thenReturn(metacardId);
    when(metacard.getResourceURI()).thenReturn(metacardUri);
    Result result = mock(Result.class);
    when(result.getMetacard()).thenReturn(metacard);
    List<Result> results = new ArrayList<Result>();
    results.add(result);

    QueryResponse queryResponse = mock(QueryResponse.class);
    when(queryResponse.getResults()).thenReturn(results);
    FederationStrategy strategy = mock(FederationStrategy.class);
    when(strategy.federate(isA(federatedSources.getClass()), isA(QueryRequest.class)))
            .thenReturn(queryResponse);

    ResourceReader resourceReader = mock(ResourceReader.class);
    Set<String> supportedSchemes = new HashSet<String>();
    supportedSchemes.add("http");
    when(resourceReader.getSupportedSchemes()).thenReturn(supportedSchemes);
    when(resourceReader.getOptions(isA(Metacard.class))).thenReturn(supportedOptions);
    List<ResourceReader> resourceReaders = new ArrayList<ResourceReader>();
    resourceReaders.add(resourceReader);

    CatalogFrameworkImpl framework = new CatalogFrameworkImpl(
            Collections.singletonList((CatalogProvider) provider), null, new ArrayList<PreIngestPlugin>(),
            new ArrayList<PostIngestPlugin>(), new ArrayList<PreQueryPlugin>(),
            new ArrayList<PostQueryPlugin>(), new ArrayList<PreResourcePlugin>(),
            new ArrayList<PostResourcePlugin>(), new ArrayList<ConnectedSource>(), federatedSources,
            resourceReaders, strategy, null, mockPoller);
    framework.bind(provider);
    framework.setId("ddf");

    Set<String> ids = new HashSet<String>();
    for (FederatedSource source : federatedSources) {
        ids.add(source.getId());
    }
    ids.add(framework.getId());

    // site name = local provider
    Map<String, Set<String>> optionsMap = framework.getResourceOptions(metacardId, localProviderName);
    LOGGER.debug("localProvider optionsMap = " + optionsMap);
    assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));

    // site name = federated site's name
    optionsMap = framework.getResourceOptions(metacardId, federatedSite1Name);
    LOGGER.debug("federatedSource optionsMap = " + optionsMap);
    assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));

    // site name = null (should default to local provider)
    optionsMap = framework.getResourceOptions(metacardId, null);
    LOGGER.debug("localProvider optionsMap = " + optionsMap);
    assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));

    // site name = empty string (should default to local provider)
    optionsMap = framework.getResourceOptions(metacardId, "");
    LOGGER.debug("localProvider optionsMap = " + optionsMap);
    assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));
}

From source file:ddf.catalog.impl.CatalogFrameworkImplTest.java

@Test
public void testGetResourceFromCache() throws Exception {
    String localProviderName = "ddf";
    String federatedSite1Name = "fed-site-1";
    String metacardId = "123";

    // The resource's URI
    URI metacardUri = new URI(
            "http:///27+Nov+12+12%3A30%3A04?MyPhotograph%0Ahttp%3A%2F%2F172.18.14.53%3A8080%2Fabc%2Fimages%2FActionable.jpg%0AMyAttachment%0Ahttp%3A%2F%2F172.18.14.53%3A8080%2Fabc#abc.xyz.dao.URLResourceOptionDataAccessObject");

    Set<String> supportedOptions = new HashSet<String>();
    supportedOptions.add("MyPhotograph");
    supportedOptions.add("MyAttachment");

    // Catalog Provider
    CatalogProvider provider = mock(CatalogProvider.class);
    when(provider.getId()).thenReturn(localProviderName);
    when(provider.isAvailable(isA(SourceMonitor.class))).thenReturn(true);
    when(provider.isAvailable()).thenReturn(true);

    // Federated Source 1
    FederatedSource federatedSource1 = mock(FederatedSource.class);
    when(federatedSource1.getId()).thenReturn(federatedSite1Name);
    when(federatedSource1.isAvailable(isA(SourceMonitor.class))).thenReturn(true);
    when(federatedSource1.isAvailable()).thenReturn(true);
    when(federatedSource1.getOptions(isA(Metacard.class))).thenReturn(supportedOptions);

    List<FederatedSource> federatedSources = new ArrayList<FederatedSource>();
    federatedSources.add(federatedSource1);

    // Mock register the provider in the container
    // Mock the source poller
    SourcePoller mockPoller = mock(SourcePoller.class);
    when(mockPoller.getCachedSource(isA(Source.class))).thenReturn(null);

    Metacard metacard = mock(Metacard.class);
    when(metacard.getId()).thenReturn(metacardId);
    when(metacard.getResourceURI()).thenReturn(metacardUri);
    Result result = mock(Result.class);
    when(result.getMetacard()).thenReturn(metacard);
    List<Result> results = new ArrayList<Result>();
    results.add(result);/* w  w  w  .j av  a 2  s  . c  o m*/

    QueryResponse queryResponse = mock(QueryResponse.class);
    when(queryResponse.getResults()).thenReturn(results);
    FederationStrategy strategy = mock(FederationStrategy.class);
    when(strategy.federate(isA(federatedSources.getClass()), isA(QueryRequest.class)))
            .thenReturn(queryResponse);

    ResourceReader resourceReader = mock(ResourceReader.class);
    Set<String> supportedSchemes = new HashSet<String>();
    supportedSchemes.add("http");
    when(resourceReader.getSupportedSchemes()).thenReturn(supportedSchemes);
    when(resourceReader.getOptions(isA(Metacard.class))).thenReturn(supportedOptions);
    List<ResourceReader> resourceReaders = new ArrayList<ResourceReader>();
    resourceReaders.add(resourceReader);

    ResourceCache resourceCache = mock(ResourceCache.class);
    Resource mockResource = mock(Resource.class);
    when(resourceCache.containsValid(isA(String.class), isA(Metacard.class))).thenReturn(true);
    when(resourceCache.getValid(isA(String.class), isA(Metacard.class))).thenReturn(mockResource);

    FrameworkProperties props = new FrameworkProperties();
    props.setCatalogProviders(Collections.singletonList((CatalogProvider) provider));
    props.setFederatedSources(Collections.singletonMap(federatedSite1Name, federatedSource1));
    props.setResourceReaders(resourceReaders);
    props.setFederationStrategy(strategy);
    props.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
    props.setSourcePoller(mockPoller);
    props.setResourceCache(resourceCache);

    props.setFilterBuilder(new GeotoolsFilterBuilder());
    CatalogFrameworkImpl framework = new CatalogFrameworkImpl(props);
    framework.bind(provider);
    framework.setId("ddf");

    Set<String> ids = new HashSet<String>();
    for (FederatedSource source : federatedSources) {
        ids.add(source.getId());
    }
    ids.add(framework.getId());

    ResourceRequestById request = new ResourceRequestById(metacardId);

    ResourceResponse response = framework.getResource(request, federatedSite1Name);

    assertThat(response, is(ResourceResponse.class));
    Metacard responseMetacard = (Metacard) response.getProperties().get("metacard");
    assertThat(responseMetacard, is(Metacard.class));
}

From source file:ddf.catalog.impl.CatalogFrameworkImplTest.java

/**
 * Tests that you can get a resource's (product) options. Covers the case where the source ID
 * specified is actually the local catalog provider's site name (so this reduces down to a
 * getResourceOptions for local provider); and the case where a federated source is specified.
 * <p>/*w w w.  java  2 s.c o m*/
 * Test for DDF-1763.
 *
 * @throws Exception
 */
@Test
public void testGetResourceOptions() throws Exception {
    String localProviderName = "ddf";
    String federatedSite1Name = "fed-site-1";
    String metacardId = "123";

    // The resource's URI
    URI metacardUri = new URI(
            "http:///27+Nov+12+12%3A30%3A04?MyPhotograph%0Ahttp%3A%2F%2F172.18.14.53%3A8080%2Fabc%2Fimages%2FActionable.jpg%0AMyAttachment%0Ahttp%3A%2F%2F172.18.14.53%3A8080%2Fabc#abc.xyz.dao.URLResourceOptionDataAccessObject");

    Set<String> supportedOptions = new HashSet<String>();
    supportedOptions.add("MyPhotograph");
    supportedOptions.add("MyAttachment");

    // Catalog Provider
    CatalogProvider provider = mock(CatalogProvider.class);
    when(provider.getId()).thenReturn(localProviderName);
    when(provider.isAvailable(isA(SourceMonitor.class))).thenReturn(true);
    when(provider.isAvailable()).thenReturn(true);

    // Federated Source 1
    FederatedSource federatedSource1 = mock(FederatedSource.class);
    when(federatedSource1.getId()).thenReturn(federatedSite1Name);
    when(federatedSource1.isAvailable(isA(SourceMonitor.class))).thenReturn(true);
    when(federatedSource1.isAvailable()).thenReturn(true);
    when(federatedSource1.getOptions(isA(Metacard.class))).thenReturn(supportedOptions);

    List<FederatedSource> federatedSources = new ArrayList<FederatedSource>();
    federatedSources.add(federatedSource1);

    // Mock register the provider in the container
    // Mock the source poller
    SourcePoller mockPoller = mock(SourcePoller.class);
    when(mockPoller.getCachedSource(isA(Source.class))).thenReturn(null);

    Metacard metacard = mock(Metacard.class);
    when(metacard.getId()).thenReturn(metacardId);
    when(metacard.getResourceURI()).thenReturn(metacardUri);
    Result result = mock(Result.class);
    when(result.getMetacard()).thenReturn(metacard);
    List<Result> results = new ArrayList<Result>();
    results.add(result);

    QueryResponse queryResponse = mock(QueryResponse.class);
    when(queryResponse.getResults()).thenReturn(results);
    FederationStrategy strategy = mock(FederationStrategy.class);
    when(strategy.federate(isA(federatedSources.getClass()), isA(QueryRequest.class)))
            .thenReturn(queryResponse);

    ResourceReader resourceReader = mock(ResourceReader.class);
    Set<String> supportedSchemes = new HashSet<String>();
    supportedSchemes.add("http");
    when(resourceReader.getSupportedSchemes()).thenReturn(supportedSchemes);
    when(resourceReader.getOptions(isA(Metacard.class))).thenReturn(supportedOptions);
    List<ResourceReader> resourceReaders = new ArrayList<ResourceReader>();
    resourceReaders.add(resourceReader);

    FrameworkProperties props = new FrameworkProperties();
    props.setCatalogProviders(Collections.singletonList((CatalogProvider) provider));
    props.setFederatedSources(Collections.singletonMap(federatedSite1Name, federatedSource1));
    props.setResourceReaders(resourceReaders);
    props.setFederationStrategy(strategy);
    props.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
    props.setSourcePoller(mockPoller);
    props.setFilterBuilder(new GeotoolsFilterBuilder());
    CatalogFrameworkImpl framework = new CatalogFrameworkImpl(props);
    framework.bind(provider);
    framework.setId("ddf");

    Set<String> ids = new HashSet<String>();
    for (FederatedSource source : federatedSources) {
        ids.add(source.getId());
    }
    ids.add(framework.getId());

    // site name = local provider
    Map<String, Set<String>> optionsMap = framework.getResourceOptions(metacardId, localProviderName);
    LOGGER.debug("localProvider optionsMap = {}", optionsMap);
    assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));

    // site name = federated site's name
    optionsMap = framework.getResourceOptions(metacardId, federatedSite1Name);
    LOGGER.debug("federatedSource optionsMap = {}", optionsMap);
    assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));

    // site name = null (should default to local provider)
    optionsMap = framework.getResourceOptions(metacardId, null);
    LOGGER.debug("localProvider optionsMap = {}", optionsMap);
    assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));

    // site name = empty string (should default to local provider)
    optionsMap = framework.getResourceOptions(metacardId, "");
    LOGGER.debug("localProvider optionsMap = {}", optionsMap);
    assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));
}

From source file:jp.terasoluna.fw.web.struts.form.DynaValidatorActionFormExTest.java

/**
 * ????s?B//from  w  w  w.java  2 s  .  c o  m
 *
 * @throws Exception ?\bh?O
 * @see junit.framework.TestCase#setUp()
 */
@SuppressWarnings("unchecked")
@Override
protected void setUp() throws Exception {
    super.setUp();
    // create formEx
    // ?set?\bh?o?Av?peB?L?qt@Cw
    this.formEx = (DynaValidatorActionFormEx) creator.create(CONFIG_FILE_PATH);

    // i[l??
    int hogeInt = 123;
    String hogeString = "data1";
    int[] hogeIntArray = { -100, 0, 10, 111 };
    String[] hogeStringArray = new String[4];
    Object[] hogeObjectArray = new Object[4];
    List<Object> hogeList = new ArrayList<Object>();
    Map<String, Object> hogeMap = new HashMap<String, Object>();
    Runnable hogeRunnable = new Runnable() {
        public void run() {
        }
    };
    boolean hogeBoolean = true;
    byte hogeByte = 1;
    char hogeChar = 'A';
    double hogeDouble = 999.9;
    float hogeFloat = 999;
    short hogeShort = 9;
    long hogeLong = 9;

    for (int i = 0; i < 4; i++) {
        hogeStringArray[i] = "data" + (i + 1);
        hogeObjectArray[i] = new Integer(i + 1);
        hogeList.add(i, "data" + (i + 1));
        hogeMap.put("field" + (i + 1), "data" + (i + 1));
    }

    String[] fields = { "hogeInt", "hogeString", "hogeIntArray", "hogeStringArray", "hogeObjectArray",
            "hogeList", "hogeMap", "hogeRunnable", "hogeBoolean", "hogeByte", "hogeChar", "hogeDouble",
            "hogeFloat", "hogeShort", "hogeLong" };
    Class[] fieldClasses = { int.class, hogeString.getClass(), hogeIntArray.getClass(),
            hogeStringArray.getClass(), hogeObjectArray.getClass(), hogeList.getClass(), hogeMap.getClass(),
            hogeRunnable.getClass(), boolean.class, byte.class, char.class, double.class, float.class,
            short.class, long.class };
    DynaProperty[] props = new DynaProperty[fields.length];
    HashMap<String, DynaProperty> propsMap = new HashMap<String, DynaProperty>();
    for (int i = 0; i < fields.length; i++) {
        props[i] = new DynaProperty(fields[i], fieldClasses[i]);
        propsMap.put(props[i].getName(), props[i]);
    }
    DynaActionFormClass dynaActionFormClass = (DynaActionFormClass) UTUtil.getPrivateField(this.formEx,
            "dynaClass");
    UTUtil.setPrivateField(dynaActionFormClass, "properties", props);
    UTUtil.setPrivateField(dynaActionFormClass, "propertiesMap", propsMap);

    Map<String, Object> map = (Map) UTUtil.getPrivateField(this.formEx, "dynaValues");
    map.put("hogeInt", hogeInt);
    map.put("hogeString", hogeString);
    map.put("hogeIntArray", hogeIntArray);
    map.put("hogeStringArray", hogeStringArray);
    map.put("hogeObjectArray", hogeObjectArray);
    map.put("hogeList", hogeList);
    map.put("hogeMap", hogeMap);
    map.put("hogeRunnable", hogeRunnable);
    map.put("hogeBoolean", hogeBoolean);
    map.put("hogeByte", hogeByte);
    map.put("hogeChar", hogeChar);
    map.put("hogeDouble", hogeDouble);
    map.put("hogeFloat", hogeFloat);
    map.put("hogeShort", hogeShort);
    map.put("hogeLong", hogeLong);
}