List of usage examples for java.util Map toString
public String toString()
From source file:com.liferay.portal.osgi.web.wab.generator.internal.processor.WabProcessorTest.java
@Test public void testSampleStrutsWab() throws Exception { File file = getFile("sample-struts-portlet.autodeployed.war"); Assert.assertNotNull(file);// w w w . ja v a 2 s . co m try (Jar jar = new Jar(file)) { Assert.assertNull(jar.getBsn()); Map<String, Resource> resources = jar.getResources(); Assert.assertEquals(resources.toString(), 217, resources.size()); } Map<String, String[]> parameters = new HashMap<>(); parameters.put("Bundle-Version", new String[] { "7.0.0.3" }); parameters.put("Web-ContextPath", new String[] { "/sample-struts-portlet" }); WabProcessor wabProcessor = new TestWabProcessor(getClassLoader(), file, parameters); File processedFile = wabProcessor.getProcessedFile(); Assert.assertNotNull(processedFile); try (Jar jar = new Jar(processedFile)) { Map<String, Map<String, Resource>> directories = jar.getDirectories(); Map<String, Resource> resources = jar.getResources(); // Check to see that the right number of resources are in the WAB Assert.assertEquals(resources.toString(), 207, resources.size()); // Check if the basic metadata is correct Assert.assertEquals("sample-struts-portlet", jar.getBsn()); Assert.assertEquals("7.0.0.3", jar.getVersion()); // Assert that the Bundle-ClassPath is properly formed to our // conventions Domain domain = Domain.domain(jar.getManifest()); Parameters bundleClassPath = domain.getBundleClassPath(); Assert.assertEquals(16, bundleClassPath.size()); Assert.assertTrue(bundleClassPath.containsKey("ext/WEB-INF/classes")); for (String bundleClassPathEntry : bundleClassPath.keySet()) { if (bundleClassPathEntry.equals("ext/WEB-INF/classes")) { Assert.assertNull(resources.get(bundleClassPathEntry)); } else if (bundleClassPathEntry.equals("WEB-INF/classes")) { Assert.assertNull(resources.get(bundleClassPathEntry)); Assert.assertTrue(directories.containsKey(bundleClassPathEntry)); } else { // Check that all the libraries on the Bundle-ClassPath // exist in the WAB Assert.assertNotNull(resources.get(bundleClassPathEntry)); } } // Check that a library which was declared in // portal-dependency-jars but which is provided by the portal's // system bundle IS NOT in the WAB Assert.assertNull(resources.get("WEB-INF/lib/commons-beanutils.jar")); Assert.assertNull(resources.get("WEB-INF/lib/commons-lang.jar")); // Check that a library which was declared in // portal-dependency-jars but which is NOT provided by the portal's // system bundle IS in the WAB Assert.assertNotNull(resources.get("WEB-INF/lib/jfreechart.jar")); Assert.assertNotNull(resources.get("WEB-INF/lib/portals-bridges.jar")); Assert.assertNotNull(resources.get("WEB-INF/lib/struts-core.jar")); // Check that JSPs were parsed to add requirements for modular // taglibs Parameters requiredCapabilities = domain.getRequireCapability(); Attrs osgiExtenderAttrs = requiredCapabilities.get("osgi.extender"); Assert.assertNotNull(osgiExtenderAttrs); Assert.assertEquals("(&(osgi.extender=jsp.taglib)" + "(uri=http://java.sun.com/portlet_2_0))", osgiExtenderAttrs.get("filter:")); Parameters importedPackages = domain.getImportPackage(); // Check basic servlet and jsp packages are imported Assert.assertTrue(importedPackages.containsKey("javax.servlet")); Assert.assertTrue(importedPackages.containsKey("javax.servlet.http")); // Since there are JSPs check that basic JSP packages are imported Assert.assertTrue(importedPackages.containsKey("javax.servlet.jsp")); Assert.assertTrue(importedPackages.containsKey("javax.servlet.jsp.tagext")); // Check if packages declared in portal property // module.framework.web.generator.default.servlet.packages are // included Assert.assertTrue(importedPackages.containsKey("com.liferay.portal.model")); Assert.assertTrue(importedPackages.containsKey("com.liferay.portal.service")); Assert.assertTrue(importedPackages.containsKey("com.liferay.portal.servlet.filters.aggregate")); Assert.assertTrue(importedPackages.containsKey("com.liferay.portal.osgi.web.servlet.jsp.compiler")); Assert.assertTrue(importedPackages.containsKey("com.liferay.portal.spring.context")); Assert.assertTrue(importedPackages.containsKey("com.liferay.portal.util")); Assert.assertTrue(importedPackages.containsKey("com.liferay.portlet")); Assert.assertTrue(importedPackages.containsKey("com.sun.el")); Assert.assertTrue(importedPackages.containsKey("org.apache.commons.chain.generic")); Assert.assertTrue(importedPackages.containsKey("org.apache.naming.java")); // Check if packages imported by code are included Assert.assertTrue( importedPackages.containsKey("com.liferay.portal.kernel.resiliency.spi.agent." + "annotation")); Assert.assertTrue(importedPackages.containsKey("com.liferay.portal.kernel.util")); // Check if packages used in the code but available on the // Bundle-ClassPath are not imported Assert.assertFalse(importedPackages.containsKey("org.apache.struts.action")); Assert.assertFalse(importedPackages.containsKey("org.jfree.chart")); // Check if packages only referenced in web.xml are imported Assert.assertTrue(importedPackages.containsKey("com.liferay.portal.kernel.servlet.filters.invoker")); Assert.assertTrue(importedPackages.containsKey("com.liferay.portal.webserver")); // Check if packages referenced by the parameter // portalListenerClasses in web.xml are imported Assert.assertTrue(importedPackages.containsKey("com.liferay.portal.kernel.spring.context")); // Check if packages referenced by the parameter // portalListenerClasses in web.xml and available on the // Bundle-Classpath are not imported Assert.assertFalse(importedPackages.containsKey("com.liferay.samplestruts.servlet")); } }
From source file:org.dataconservancy.dcs.ingest.file.StagedFileUploadManagerTest.java
@Test public void digestsRecordedInFileEntityTest() throws Exception { Map<String, String> metadata = new HashMap<String, String>(); HttpHeaderUtil.addDigest("MD5", MD5, metadata); HttpHeaderUtil.addDigest("SHA", SHA, metadata); Collection<DcsFixity> fixity = parseContent( mgr.deposit(IOUtils.toInputStream(BASIC_CONTENT), "text/plain", null, metadata)).getFiles() .iterator().next().getFixity(); Map<String, String> fixtyValues = new HashMap<String, String>(); for (DcsFixity f : fixity) { fixtyValues.put(f.getAlgorithm(), f.getValue()); }/*from w ww . ja v a2 s . com*/ assertEquals(fixtyValues.toString(), 2, fixity.size()); assertEquals(MD5_HEX, fixtyValues.get("MD5")); assertEquals(SHA_HEX, fixtyValues.get("SHA")); }
From source file:com.scvngr.levelup.core.net.RequestUtilsTest.java
/** * Test {@link com.scvngr.levelup.core.net.RequestUtils#addApiKeyToRequestQueryParams}. *///from w w w .j a v a2 s . c o m @SmallTest public void testAddApiKeyToRequestQueryParams() { final Map<String, String> expected = new HashMap<String, String>(); final Map<String, String> params = new HashMap<String, String>(); final Context context = NullUtils.nonNullContract(getContext()); expected.put(RequestUtils.PARAM_API_KEY, context.getString(R.string.levelup_api_key)); RequestUtils.addApiKeyToRequestQueryParams(context, params); assertEquals(expected.toString(), params.toString()); }
From source file:edu.ucuenca.authorsrelatedness.Distance.java
public synchronized String Http2(String s, Map<String, String> mp) throws SQLException, IOException { String md = s + mp.toString(); String get = Cache.getInstance().get(md); String resp = ""; if (get != null) { resp = get;/* www .j a va2 s . c om*/ } else { HttpClient client = new HttpClient(); PostMethod method = new PostMethod(s); method.getParams().setContentCharset("utf-8"); //Add any parameter if u want to send it with Post req. for (Entry<String, String> mcc : mp.entrySet()) { method.addParameter(mcc.getKey(), mcc.getValue()); } int statusCode = client.executeMethod(method); if (statusCode != -1) { InputStream in = method.getResponseBodyAsStream(); final Scanner reader = new Scanner(in, "UTF-8"); while (reader.hasNextLine()) { final String line = reader.nextLine(); resp += line + "\n"; } reader.close(); Cache.getInstance().put(md, resp); } } return resp; }
From source file:org.finra.herd.service.helper.BusinessObjectFormatExternalInterfaceDescriptiveInformationHelperTest.java
@Test public void testCreateBusinessObjectFormatExternalInterfaceDescriptiveInformationFromEntities() { // Create a velocity template for the external interface entity. String velocityTemplateDescription = "${namespace}#${businessObjectDefinitionName}#${businessObjectFormatUsage}#${businessObjectFormatFileType}#" + "${businessObjectFormatAttributes}#${partitionColumnNames}#${partitionKeyGroup}#$StringUtils.isNotEmpty($namespace)"; // Get a list of partition columns that is larger than number of partitions supported by business object data registration. List<SchemaColumn> partitionColumns = schemaColumnDaoTestHelper.getTestPartitionColumns(); assertTrue(CollectionUtils.size(partitionColumns) > BusinessObjectDataEntity.MAX_SUBPARTITIONS + 1); // Get a list of regular columns. List<SchemaColumn> regularColumns = schemaColumnDaoTestHelper.getTestSchemaColumns(); // Create a list of attributes List<Attribute> attributes = Lists.newArrayList(new Attribute(ATTRIBUTE_NAME, ATTRIBUTE_VALUE), new Attribute(ATTRIBUTE_NAME_2, ATTRIBUTE_VALUE_2)); // Create a business object format entity. BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper .createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, FORMAT_DESCRIPTION, NO_FORMAT_DOCUMENT_SCHEMA, NO_FORMAT_DOCUMENT_SCHEMA_URL, LATEST_VERSION_FLAG_SET, partitionColumns.get(0).getName(), PARTITION_KEY_GROUP, attributes, SCHEMA_DELIMITER_PIPE, SCHEMA_COLLECTION_ITEMS_DELIMITER_COMMA, SCHEMA_MAP_KEYS_DELIMITER_HASH, SCHEMA_ESCAPE_CHARACTER_BACKSLASH, SCHEMA_NULL_VALUE_BACKSLASH_N, regularColumns, partitionColumns);/* w w w .ja v a 2 s . c om*/ // Create an external interface entity. ExternalInterfaceEntity externalInterfaceEntity = externalInterfaceDaoTestHelper .createExternalInterfaceEntity(EXTERNAL_INTERFACE); externalInterfaceEntity.setDisplayName(DISPLAY_NAME_FIELD); externalInterfaceEntity.setDescription(velocityTemplateDescription); // Create a business object format to external interface mapping entity. businessObjectFormatExternalInterfaceDaoTestHelper.createBusinessObjectFormatExternalInterfaceEntity( businessObjectFormatEntity, externalInterfaceEntity); // Call the method under test. BusinessObjectFormatExternalInterfaceDescriptiveInformation result = businessObjectFormatExternalInterfaceDescriptiveInformationHelper .createBusinessObjectFormatExternalInterfaceDescriptiveInformationFromEntities( businessObjectFormatEntity, externalInterfaceEntity); // Validate the results. assertEquals(result.getBusinessObjectFormatExternalInterfaceKey().getNamespace(), NAMESPACE); assertEquals(result.getBusinessObjectFormatExternalInterfaceKey().getBusinessObjectDefinitionName(), BDEF_NAME); assertEquals(result.getBusinessObjectFormatExternalInterfaceKey().getBusinessObjectFormatUsage(), FORMAT_USAGE_CODE); assertEquals(result.getBusinessObjectFormatExternalInterfaceKey().getBusinessObjectFormatFileType(), FORMAT_FILE_TYPE_CODE); assertEquals(result.getBusinessObjectFormatExternalInterfaceKey().getExternalInterfaceName(), EXTERNAL_INTERFACE); assertEquals(result.getExternalInterfaceDisplayName(), DISPLAY_NAME_FIELD); String[] descriptionTemplateReplacementValues = result.getExternalInterfaceDescription().split("#"); // ${namespace} assertEquals("Namespace not equal to replacement.", descriptionTemplateReplacementValues[0], NAMESPACE); // ${businessObjectDefinitionName} assertEquals("Business object definition name not equal to replacement.", descriptionTemplateReplacementValues[1], BDEF_NAME); // ${businessObjectFormatUsage} assertEquals("Usage not equal to replacement.", descriptionTemplateReplacementValues[2], FORMAT_USAGE_CODE); // ${businessObjectFormatFileType} assertEquals("File type not equal to replacement.", descriptionTemplateReplacementValues[3], FORMAT_FILE_TYPE_CODE); // ${businessObjectFormatAttributes} Map<String, String> attributesMap = Maps.newLinkedHashMap(); for (Attribute attribute : attributes) { attributesMap.put(attribute.getName(), attribute.getValue()); } assertEquals("Attributes not equal to replacement.", descriptionTemplateReplacementValues[4], attributesMap.toString()); // ${partitionColumnNames} List<String> partitionColumnNames = Lists.newArrayList(); for (SchemaColumnEntity schemaColumn : businessObjectFormatEntity.getSchemaColumns()) { if (schemaColumn.getPartitionLevel() != null) { partitionColumnNames.add(schemaColumn.getName()); } } assertEquals("Partitions not equal to replacement.", descriptionTemplateReplacementValues[5], partitionColumnNames.toString()); // ${partitionKeyGroup} assertEquals("Partition key group not equal to replacement.", descriptionTemplateReplacementValues[6], PARTITION_KEY_GROUP); // $StringUtils assertEquals("StringUtils not equal to replacement.", descriptionTemplateReplacementValues[7], "true"); }
From source file:com.scooterframework.web.controller.DefaultContentHandler.java
protected <K, V> String convertMapToString(Map<K, V> map, String format) { StringBuilder sb = new StringBuilder(); if ("json".equalsIgnoreCase(format)) { sb.append((new JSONObject(map)).toString()); } else if ("xml".equalsIgnoreCase(format)) { try {/* w w w .j a v a 2 s.co m*/ sb.append(XML.toString((new JSONObject(map)))); } catch (JSONException ex) { log.error("Failed to conver to xml string: " + ex.getMessage()); } } else { sb.append(map.toString()); } return sb.toString(); }
From source file:org.datacleaner.monitor.server.controllers.ResultModificationControllerTest.java
public void testModifyBothDateAndJob() throws Exception { ResultModificationPayload input = new ResultModificationPayload(); input.setJob("email_standardizer"); input.setDate("1355698800000"); Map<String, String> response = resultModificationController.modifyResult("tenant1", "product_profiling-3", input);/* www. j a v a2 s . co m*/ assertEquals( "{new_result_name=email_standardizer-1355698800000.analysis.result.dat, " + "old_result_name=product_profiling-3.analysis.result.dat, " + "repository_url=/tenant1/results/email_standardizer-1355698800000.analysis.result.dat}", response.toString()); assertNotNull(repository .getRepositoryNode("/tenant1/results/email_standardizer-1355698800000.analysis.result.dat")); RepositoryFile executionLogFile = (RepositoryFile) repository .getRepositoryNode("/tenant1/results/email_standardizer-1355698800000.analysis.execution.log.xml"); assertNotNull(executionLogFile); executionLogFile.readFile(new Action<InputStream>() { @Override public void run(InputStream inputStream) throws Exception { ExecutionLog executionLog = new JaxbExecutionLogReader().read(inputStream, new JobIdentifier("email_standardizer"), new TenantIdentifier("tenant1")); assertEquals("email_standardizer-1355698800000", executionLog.getResultId()); } }); }
From source file:org.jasig.portlet.notice.service.rest.RestfulJsonNotificationService.java
@Override public NotificationResponse fetch(PortletRequest req) { NotificationResponse rslt = EMPTY_RESPONSE; // default is empty final PortletPreferences prefs = req.getPreferences(); final Map<String, String> params = createParameters(req); final RequestCallback requestCallback = new RequestCallbackImpl(req); final String[] serviceUrls = prefs.getValues(SERVICE_URLS_PREFERENCE, new String[0]); for (final String url : serviceUrls) { if (log.isDebugEnabled()) { log.debug("Invoking uri '" + url + "' with the following parameters: " + params.toString()); }//from w w w . j a v a2s .c o m try { final NotificationResponse response = restTemplate.execute(url, HttpMethod.GET, requestCallback, responseExtractor, params); rslt = rslt.combine(response); } catch (Exception e) { final String msg = "Failed to invoke the following service at '" + url + "' for user " + usernameFinder.findUsername(req); log.error(msg, e); rslt = prepareErrorResponse(getName(), "Service Unavailable"); } } return rslt; }
From source file:edu.cornell.mannlib.vitro.webapp.controller.freemarker.ListFauxPropertiesController.java
@Override protected ResponseValues processRequest(VitroRequest vreq) { Map<String, Object> body = new HashMap<String, Object>(); try {//from w w w. j ava 2s. co m String displayOption = ""; if (vreq.getParameter("displayOption") != null) { displayOption = vreq.getParameter("displayOption"); } else { displayOption = "listing"; } body.put("displayOption", displayOption); if (displayOption.equals("listing")) { body.put("pageTitle", "Faux Property Listing"); } else { body.put("pageTitle", "Faux Properties by Base Property"); } opDao = vreq.getUnfilteredAssertionsWebappDaoFactory().getObjectPropertyDao(); fpDao = vreq.getUnfilteredAssertionsWebappDaoFactory().getFauxPropertyDao(); pgDao = vreq.getUnfilteredAssertionsWebappDaoFactory().getPropertyGroupDao(); List<ObjectProperty> objectProps = null; objectProps = opDao.getRootObjectProperties(); Map<String, Object> allFauxProps = new TreeMap<String, Object>(); // get the faux depending on the display option if (displayOption.equals("listing")) { allFauxProps = getFauxPropertyList(objectProps); } else { allFauxProps = getFauxByBaseList(objectProps); } log.debug(allFauxProps.toString()); if (notFoundMessage.length() == 0) { body.put("message", notFoundMessage); } else { body.put("fauxProps", allFauxProps); } } catch (Throwable t) { t.printStackTrace(); } return new TemplateResponseValues(TEMPLATE_NAME, body); }
From source file:org.finra.dm.dao.impl.BaseJpaDaoImpl.java
@Override public <T> T findUniqueByNamedProperties(Class<T> entityClass, Map<String, ?> params) { Validate.notNull(entityClass);// w w w . ja va 2s. c o m Validate.notEmpty(params); List<T> resultList = findByNamedProperties(entityClass, params); Validate.isTrue(resultList.isEmpty() || resultList.size() == 1, "Found more than one persistent instance of type " + StringUtils.unqualify(entityClass.getName() + " with parameters " + params.toString())); return resultList.size() == 1 ? resultList.get(0) : null; }