@Override public void removeAll(Collection<byte[]> removing) { awaitInit(); Set<Long> removed = new HashSet<>(); for(final Map.Entry<Long, byte[]> e : hashes.entrySet()) { byte[] hash = IterableUtils.find(removing, hash1 -> FastByteComparisons.compareTo(hash1, 0, 32, e.getValue(), 0, 32) == 0); if(hash != null) { removed.add(e.getKey()); } } index.removeAll(removed); for(Long idx : removed) { hashes.remove(idx); } dbCommit(); }
protected static ObjectName getObjectName(final MBeanServerConnection connection, final String remoteContext, final Class objectClass) throws IOException { Set<ObjectName> names = connection.queryNames(null, null); return IterableUtils.find(names, o -> { if (!Objects.equals(remoteContext, o.getDomain())) { return false; } MBeanInfo info; try { info = connection.getMBeanInfo(o); } catch (Exception e) { throw new JmxControlException(e); } return Objects.equals(objectClass.getName(), info.getClassName()); }); }
@Override public Iterable<FacilityStateSnapshot> findLastByFacilityStatesUpdatedSince(Iterable<FacilityState> facilityStates, long timestamp) { final Set<FacilityState> states = new TreeSet<>(IterableUtils.toList(facilityStates)); final List<FacilityStateSnapshot> snapshots = new LinkedList<>(); synchronized (facilityStateSnapshots) { for (Entry<Long, Collection<FacilityStateSnapshot>> entry : facilityStateSnapshots.asMap().entrySet()) { final Iterator<FacilityStateSnapshot> iterator = entry.getValue().iterator(); if (iterator.hasNext()) { final FacilityStateSnapshot snapshot = iterator.next(); if (states.contains(snapshot.getState()) && snapshot.getTimestamp() > timestamp) { snapshots.add(snapshot); } } } } return snapshots; }
/** * Creates a business object definition column from the persisted entity. * * @param businessObjectDefinitionColumnEntity the business object definition column entity * @param includeId boolean value indicating whether or not to include the id * @param fields set of field parameters to include on the business object definition column * * @return the business object definition column */ private BusinessObjectDefinitionColumn createBusinessObjectDefinitionColumnFromEntity( BusinessObjectDefinitionColumnEntity businessObjectDefinitionColumnEntity, boolean includeId, Set<String> fields) { BusinessObjectDefinitionColumn businessObjectDefinitionColumn = new BusinessObjectDefinitionColumn(); if (includeId) { businessObjectDefinitionColumn.setId(businessObjectDefinitionColumnEntity.getId()); } businessObjectDefinitionColumn.setBusinessObjectDefinitionColumnKey(getBusinessObjectDefinitionColumnKey(businessObjectDefinitionColumnEntity)); if (fields.contains(DESCRIPTION_FIELD)) { businessObjectDefinitionColumn.setDescription(businessObjectDefinitionColumnEntity.getDescription()); } if (fields.contains(SCHEMA_COLUMN_NAME_FIELD) && CollectionUtils.isNotEmpty(businessObjectDefinitionColumnEntity.getSchemaColumns())) { businessObjectDefinitionColumn.setSchemaColumnName(IterableUtils.get(businessObjectDefinitionColumnEntity.getSchemaColumns(), 0).getName()); } return businessObjectDefinitionColumn; }
@Test public void testUpdateBusinessObjectDataAttributesAttributeAdded() { // Create a list of attributes. List<Attribute> attributes = Arrays.asList(new Attribute(ATTRIBUTE_NAME, ATTRIBUTE_VALUE)); // Create a business object data entity without attributes. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); businessObjectDataEntity.setAttributes(new ArrayList<>()); // Call the method under test. attributeDaoHelper.updateBusinessObjectDataAttributes(businessObjectDataEntity, attributes); // Verify the external calls. verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(1, CollectionUtils.size(businessObjectDataEntity.getAttributes())); BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = IterableUtils.get(businessObjectDataEntity.getAttributes(), 0); assertEquals(businessObjectDataEntity, businessObjectDataAttributeEntity.getBusinessObjectData()); assertEquals(ATTRIBUTE_NAME, businessObjectDataAttributeEntity.getName()); assertEquals(ATTRIBUTE_VALUE, businessObjectDataAttributeEntity.getValue()); }
@Test public void testUpdateBusinessObjectDataAttributesAttributeValueNotUpdated() { // Create a business object data attribute entity. BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = new BusinessObjectDataAttributeEntity(); businessObjectDataAttributeEntity.setName(ATTRIBUTE_NAME); businessObjectDataAttributeEntity.setValue(ATTRIBUTE_VALUE); // Create a business object data entity that contains one attribute entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); List<BusinessObjectDataAttributeEntity> businessObjectDataAttributeEntities = new ArrayList<>(); businessObjectDataEntity.setAttributes(businessObjectDataAttributeEntities); businessObjectDataAttributeEntities.add(businessObjectDataAttributeEntity); // Call the method under test. attributeDaoHelper.updateBusinessObjectDataAttributes(businessObjectDataEntity, Arrays.asList(new Attribute(ATTRIBUTE_NAME, ATTRIBUTE_VALUE))); // Verify the external calls. verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(1, CollectionUtils.size(businessObjectDataEntity.getAttributes())); BusinessObjectDataAttributeEntity result = IterableUtils.get(businessObjectDataEntity.getAttributes(), 0); assertEquals(ATTRIBUTE_NAME, result.getName()); assertEquals(ATTRIBUTE_VALUE, result.getValue()); }
@Test public void testUpdateBusinessObjectDataAttributesAttributeValueUpdated() { // Create a business object data attribute entity. BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = new BusinessObjectDataAttributeEntity(); businessObjectDataAttributeEntity.setName(ATTRIBUTE_NAME); businessObjectDataAttributeEntity.setValue(ATTRIBUTE_VALUE); // Create a business object data entity that contains one attribute entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); List<BusinessObjectDataAttributeEntity> businessObjectDataAttributeEntities = new ArrayList<>(); businessObjectDataEntity.setAttributes(businessObjectDataAttributeEntities); businessObjectDataAttributeEntities.add(businessObjectDataAttributeEntity); // Call the method under test. attributeDaoHelper.updateBusinessObjectDataAttributes(businessObjectDataEntity, Arrays.asList(new Attribute(ATTRIBUTE_NAME, ATTRIBUTE_VALUE_2))); // Verify the external calls. verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(1, CollectionUtils.size(businessObjectDataEntity.getAttributes())); BusinessObjectDataAttributeEntity result = IterableUtils.get(businessObjectDataEntity.getAttributes(), 0); assertEquals(ATTRIBUTE_NAME, result.getName()); assertEquals(ATTRIBUTE_VALUE_2, result.getValue()); }
/** * Update the state of input files. * Change the state value for the input file specified. If the name is not associated with any input file nothing happen. <p> There is not check on the file existence and real state which is delegated to the caller object. * * @param name File name * @param aStatus New state */ public final void updateInputFileStatus( final String name, final TaskFile.FILESTATUS aStatus) { TaskFileInput tfi = IterableUtils.find(inputFiles, new Predicate<TaskFileInput>() { @Override public boolean evaluate(final TaskFileInput t) { return t.getName().equals(name); } }); if (tfi != null) { tfi.setStatus(aStatus); lastChange = new Date(); setChanged(); notifyObservers(); } }
@Before public void add_infra_should_create_a_new_infra() { Infrastructure infra = new Infrastructure(); infra.setDescription("Test description"); infra.setGroup("group"); HttpEntity<InfrastructureResource> resp = this.infrastructureController.addInfrastructure(infra); Assert.assertNotNull(resp); Assert.assertNotNull(resp.getBody()); InfrastructureResource infraReturned = resp.getBody(); Assert.assertNotNull(infraReturned); Assert.assertNotNull(infraReturned.getId()); Assert.assertEquals(infra.getDescription(), infraReturned.getDescription()); Assert.assertEquals(infra.getCrm(), infraReturned.getCrm()); Assert.assertEquals(infra.getGroup(), infraReturned.getGroup()); infraId = infraReturned.getInfraId(); List<InfrastructureResource> infras = IterableUtils.toList(this.infrastructureController.getInfrastructures(null, null, new PagedResourcesAssembler<Infrastructure>(resolver, null))); Assert.assertNotNull(infras); Assert.assertEquals(1, infras.size()); }
@Test public void add_zone_should_create_a_new_zone() { Zone zone = new Zone(); zone.setDescription("Test description"); zone.setInfraId(infraId); zone.setIp(0xC0A80001L); HttpEntity<ZoneResource> resp = this.controller.addZone(infraId, zone); Assert.assertNotNull(resp); Assert.assertNotNull(resp.getBody()); ZoneResource zoneReturned = resp.getBody(); Assert.assertNotNull(zoneReturned); Assert.assertNotNull(zoneReturned.getId()); Assert.assertEquals(zone.getDescription(), zoneReturned.getDescription()); Assert.assertEquals(zone.getInfraId(), zoneReturned.getInfraId()); Assert.assertEquals(zone.getIp(), zoneReturned.getIp()); Assert.assertEquals(3, zoneReturned.getLinks().size()); id = zoneReturned.getZoneId(); List<ZoneResource> zones = IterableUtils.toList(this.controller.getZones(infraId, null, new PagedResourcesAssembler<Zone>(resolver, null))); Assert.assertNotNull(zones); Assert.assertEquals(1, zones.size()); }
@Test public void testUpdateWithGHZ5AndUS() throws Exception { // setup int colorSelected = ContextCompat.getColor(mainActivity, R.color.connected); int colorNotSelected = ContextCompat.getColor(mainActivity, R.color.connected_background); Pair<WiFiChannel, WiFiChannel> selectedKey = WiFiBand.GHZ5.getWiFiChannels().getWiFiChannelPairs().get(0); when(configuration.getWiFiChannelPair()).thenReturn(selectedKey); when(settings.getCountryCode()).thenReturn(Locale.US.getCountry()); when(settings.getWiFiBand()).thenReturn(WiFiBand.GHZ5); when(settings.getSortBy()).thenReturn(SortBy.CHANNEL); // execute fixture.update(WiFiData.EMPTY); // validate verify(layout).setVisibility(View.VISIBLE); IterableUtils.forEach(views.keySet(), new PairUpdateClosure(selectedKey, colorSelected, colorNotSelected)); IterableUtils.forEach(ChannelGraphNavigation.ids.values(), new IntegerUpdateClosure()); verify(settings).getCountryCode(); verify(settings, times(2)).getWiFiBand(); verify(settings).getSortBy(); verify(configuration).getWiFiChannelPair(); }
@Test public void add_range_should_create_a_new_range() { Range range = new Range(); range.setDescription("Test description"); range.setInfraId(infraId); range.setZoneId(zoneId); range.setSize(65536L); range.setIp(0xC0A80000L); HttpEntity<RangeResource> resp = this.controller.addRange(infraId, zoneId, range); Assert.assertNotNull(resp); Assert.assertNotNull(resp.getBody()); RangeResource rangeReturned = resp.getBody(); Assert.assertNotNull(rangeReturned); Assert.assertNotNull(rangeReturned.getId()); Assert.assertEquals(range.getDescription(), rangeReturned.getDescription()); Assert.assertEquals(range.getInfraId(), rangeReturned.getInfraId()); Assert.assertEquals(range.getZoneId(), rangeReturned.getZoneId()); Assert.assertEquals(range.getIp(), rangeReturned.getIp()); Assert.assertEquals(range.getSize(), rangeReturned.getSize()); Assert.assertEquals(4, rangeReturned.getLinks().size()); id = rangeReturned.getRangeId(); List<RangeResource> ranges = IterableUtils.toList(this.controller.getRanges(infraId, zoneId, null, new PagedResourcesAssembler<Range>(resolver, null))); Assert.assertNotNull(ranges); Assert.assertEquals(1, ranges.size()); }
@After public void z3_delete_zone_should_work() { this.repository.deleteAll(); this.subnetController.deleteSubnet(infraId, subnetId, null); this.zoneController.deleteZone(infraId, zoneId); List<ZoneResource> zones = IterableUtils.toList(this.zoneController.getZones(infraId, null, new PagedResourcesAssembler<Zone>(resolver, null))); Assert.assertNotNull(zones); Assert.assertEquals(0, zones.size()); this.infrastructureController.deleteInfrastructure(infraId); List<InfrastructureResource> infras = IterableUtils.toList(this.infrastructureController.getInfrastructures(null, null, new PagedResourcesAssembler<Infrastructure>(resolver, null))); Assert.assertNotNull(infras); Assert.assertEquals(0, infras.size()); }
@Test public void add_infra_should_create_a_new_infra() { Infrastructure infra = new Infrastructure(); infra.setDescription("Test description"); infra.setGroup("group"); HttpEntity<InfrastructureResource> resp = this.controller.addInfrastructure(infra); Assert.assertNotNull(resp); Assert.assertNotNull(resp.getBody()); InfrastructureResource infraReturned = resp.getBody(); Assert.assertNotNull(infraReturned); Assert.assertNotNull(infraReturned.getId()); Assert.assertEquals(infra.getDescription(), infraReturned.getDescription()); Assert.assertEquals(infra.getCrm(), infraReturned.getCrm()); Assert.assertEquals(infra.getGroup(), infraReturned.getGroup()); Assert.assertEquals(3, infraReturned.getLinks().size()); id = infraReturned.getInfraId(); List<InfrastructureResource> infras = IterableUtils.toList(this.controller.getInfrastructures(null, null, new PagedResourcesAssembler<Infrastructure>(resolver, null))); Assert.assertNotNull(infras); Assert.assertEquals(1, infras.size()); }
@Test public void add_infra_twice_should_create_a_new_infra() { add_infra_should_create_a_new_infra(); Infrastructure infra = new Infrastructure(); infra.setDescription("Test description 3"); infra.setGroup("group2"); HttpEntity<InfrastructureResource> response = this.controller.addInfrastructure(infra); Assert.assertNotNull(response); Assert.assertNotNull(response.getBody()); InfrastructureResource infraReturned = response.getBody(); Assert.assertNotNull(infraReturned); Assert.assertNotNull(infraReturned.getId()); Assert.assertEquals(infra.getDescription(), infraReturned.getDescription()); Assert.assertEquals(infra.getCrm(), infraReturned.getCrm()); Assert.assertEquals(infra.getGroup(), infraReturned.getGroup()); Assert.assertEquals(3, infraReturned.getLinks().size()); id2 = infraReturned.getInfraId(); List<InfrastructureResource> infras = IterableUtils.toList(this.controller.getInfrastructures(null, null, new PagedResourcesAssembler<Infrastructure>(resolver, null))); Assert.assertNotNull(infras); Assert.assertEquals(2, infras.size()); }
@Override public Iterable<String> autoComplete(String buffer) { Iterable<String> candidates = IterableUtils.emptyIterable(); final String lastToken = getLastToken(buffer); if(StringUtils.isNotEmpty(lastToken)) { if (isDoc(lastToken)) { candidates = autoCompleteDoc(lastToken.substring(1)); } else if (isMagic(lastToken)) { candidates = autoCompleteMagic(lastToken); } else { candidates = autoCompleteNormal(lastToken); } } return candidates; }
public Value findField(final String fieldName){ Value value; value = IterableUtils.find(this, new Predicate<Value>() { @Override public boolean evaluate(Value object) { return object.getMetadata().getName().equals(fieldName); } }); return value; }
/** * Gets the first json element, if any, in the list. Else returns null * * @param elements the json elements * @return the first json element in the list */ public JsonElement getFirst(Iterable<JsonElement> elements) { JsonElement first = null; if (!IterableUtils.isEmpty(elements)) { first = IterableUtils.get(elements, 0); } return first; }
public AttributePermissionVariant getPermissionVariant(final String attribute) { AttributeTarget attrTarget = IterableUtils.find(getPermissions(), object -> object != null && attribute.equals(object.getId())); if (attrTarget != null) return attrTarget.getPermissionVariant(); else return null; }
public void assignPermissionVariant(final String attribute, AttributePermissionVariant permissionVariant) { AttributeTarget attrTarget = IterableUtils.find(getPermissions(), object -> object != null && attribute.equals(object.getId())); if (attrTarget != null) { attrTarget.setPermissionVariant(permissionVariant); } }
protected void selectAttachmentDialog(SendingMessage message) { openLookup("sys$SendingMessage.attachments", items -> { if (items.size() == 1) { exportFile((SendingAttachment) IterableUtils.get(items, 0)); } }, OpenType.DIALOG, ParamsMap.of("message", message)); }
protected void addDynamicAttributes(Table component, Datasource ds, List<Table.Column> availableColumns) { if (metadataTools.isPersistent(ds.getMetaClass())) { Set<CategoryAttribute> attributesToShow = dynamicAttributesGuiTools.getAttributesToShowOnTheScreen(ds.getMetaClass(), context.getFullFrameId(), component.getId()); if (CollectionUtils.isNotEmpty(attributesToShow)) { ds.setLoadDynamicAttributes(true); for (CategoryAttribute attribute : attributesToShow) { final MetaPropertyPath metaPropertyPath = DynamicAttributesUtils.getMetaPropertyPath(ds.getMetaClass(), attribute); Object columnWithSameId = IterableUtils.find(availableColumns, o -> o.getId().equals(metaPropertyPath)); if (columnWithSameId != null) { continue; } final Table.Column column = new Table.Column(metaPropertyPath); column.setCaption(LocaleHelper.isLocalizedValueDefined(attribute.getLocaleNames()) ? attribute.getLocaleName() : StringUtils.capitalize(attribute.getName())); if (attribute.getDataType().equals(PropertyType.STRING)) { column.setMaxTextLength(clientConfig.getDynamicAttributesTableColumnMaxTextLength()); } if (attribute.getDataType().equals(PropertyType.ENUMERATION)) { column.setFormatter(value -> LocaleHelper.getEnumLocalizedValue((String) value, attribute.getEnumerationLocales()) ); } component.addColumn(column); } } dynamicAttributesGuiTools.listenDynamicAttributesChanges(ds); } }
/** * Returns the index of the binding for the given variable. */ public int findBinding( final String name) { return IterableUtils.indexOf ( varBindings_, new Predicate<VarBinding>() { @SuppressWarnings("deprecation") public boolean evaluate( VarBinding binding) { return ObjectUtils.equals( binding.getVar(), name); } }); }
/** * Returns the number of test cases that include the given tuple. */ private static int getTestCasesIncluding( FunctionTestDef testDef, final Tuple tuple) { return (int) IterableUtils.countMatches ( IteratorUtils.toList( testDef.getTestCases()), new Predicate<TestCase>() { public boolean evaluate( TestCase testCase) { return testCaseIncludes( testCase, tuple); } }); }
Set<WiFiDetail> addSeriesData(@NonNull GraphViewWrapper graphViewWrapper, @NonNull List<WiFiDetail> wiFiDetails, int levelMax) { Set<WiFiDetail> inOrder = new TreeSet<>(wiFiDetails); IterableUtils.forEach(inOrder, new AddDataClosure(graphViewWrapper, levelMax)); adjustData(graphViewWrapper, inOrder); Set<WiFiDetail> result = getNewSeries(inOrder); xValue++; if (scanCount < GraphConstants.MAX_SCAN_COUNT) { scanCount++; } if (scanCount == 2) { graphViewWrapper.setHorizontalLabelsVisible(true); } return result; }
/** * Asserts that the target business object data that is created is using the target storage name that is specified in the request. */ @Test public void testInitiateUploadSingleAssertUseTargetStorageInRequest() { // Create database entities required for testing. uploadDownloadServiceTestHelper.createDatabaseEntitiesForUploadDownloadTesting(); StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(STORAGE_NAME_3); storageEntity.getAttributes().add(storageDaoTestHelper .createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), "testBucketName")); storageEntity.getAttributes().add(storageDaoTestHelper .createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), "$environment/$namespace/$businessObjectDataPartitionValue")); storageEntity.getAttributes().add(storageDaoTestHelper .createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KMS_KEY_ID), "arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012")); // Initiate a file upload. UploadSingleInitiationRequest uploadSingleInitiationRequest = uploadDownloadServiceTestHelper.createUploadSingleInitiationRequest(); uploadSingleInitiationRequest.setTargetStorageName(STORAGE_NAME_3); UploadSingleInitiationResponse resultUploadSingleInitiationResponse = uploadDownloadService.initiateUploadSingle(uploadSingleInitiationRequest); // Validate the returned object. uploadDownloadServiceTestHelper .validateUploadSingleInitiationResponse(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, NAMESPACE, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION_2, businessObjectDefinitionServiceTestHelper.getNewAttributes(), FILE_NAME, FILE_SIZE_1_KB, STORAGE_NAME_3, resultUploadSingleInitiationResponse); BusinessObjectDataEntity targetBusinessObjectDataEntity = businessObjectDataDao.getBusinessObjectDataByAltKey( new BusinessObjectDataKey(NAMESPACE, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION_2, resultUploadSingleInitiationResponse.getTargetBusinessObjectData().getPartitionValue(), null, 0)); assertNotNull(targetBusinessObjectDataEntity); assertNotNull(targetBusinessObjectDataEntity.getStorageUnits()); assertEquals(1, targetBusinessObjectDataEntity.getStorageUnits().size()); StorageUnitEntity storageUnit = IterableUtils.get(targetBusinessObjectDataEntity.getStorageUnits(), 0); assertNotNull(storageUnit); assertNotNull(storageUnit.getStorage()); assertEquals(STORAGE_NAME_3, storageUnit.getStorage().getName()); }
@Test public void testInitiateDownloadSingleMultipleStorageFilesExist() { // Create the upload data. UploadSingleInitiationResponse uploadSingleInitiationResponse = uploadDownloadServiceTestHelper.createUploadedFileData(BusinessObjectDataStatusEntity.VALID); // Get the target business object data entity. BusinessObjectDataEntity targetBusinessObjectDataEntity = businessObjectDataDao .getBusinessObjectDataByAltKey(businessObjectDataHelper.getBusinessObjectDataKey(uploadSingleInitiationResponse.getTargetBusinessObjectData())); // Get the target bushiness object data storage unit. StorageUnitEntity targetStorageUnitEntity = IterableUtils.get(targetBusinessObjectDataEntity.getStorageUnits(), 0); // Add a second storage file to the target business object data storage unit. storageFileDaoTestHelper.createStorageFileEntity(targetStorageUnitEntity, FILE_NAME_2, FILE_SIZE_1_KB, ROW_COUNT_1000); // Try to initiate a single file download when business object data has more than one storage file. try { // Initiate the download against the uploaded data (i.e. the target business object data). initiateDownload(uploadSingleInitiationResponse.getTargetBusinessObjectData()); fail("Suppose to throw an IllegalArgumentException when business object has more than one storage file."); } catch (IllegalArgumentException e) { BusinessObjectData businessObjectData = uploadSingleInitiationResponse.getTargetBusinessObjectData(); assertEquals(String.format("Found 2 registered storage files when expecting one in \"%s\" storage for the business object data {%s}.", targetStorageUnitEntity.getStorage().getName(), businessObjectDataServiceTestHelper .getExpectedBusinessObjectDataKeyAsString(businessObjectDataHelper.getBusinessObjectDataKey(businessObjectData))), e.getMessage()); } }
@Test public void testUpdateBusinessObjectDataAttributesAttributeValueUpdatedAttributeNamesEqualIgnoreCase() { // Create a business object data attribute entity. BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = new BusinessObjectDataAttributeEntity(); businessObjectDataAttributeEntity.setName(ATTRIBUTE_NAME.toUpperCase()); businessObjectDataAttributeEntity.setValue(ATTRIBUTE_VALUE); // Create a business object data entity that contains one attribute entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); List<BusinessObjectDataAttributeEntity> businessObjectDataAttributeEntities = new ArrayList<>(); businessObjectDataEntity.setAttributes(businessObjectDataAttributeEntities); businessObjectDataAttributeEntities.add(businessObjectDataAttributeEntity); // Call the method under test. attributeDaoHelper .updateBusinessObjectDataAttributes(businessObjectDataEntity, Arrays.asList(new Attribute(ATTRIBUTE_NAME.toLowerCase(), ATTRIBUTE_VALUE_2))); // Verify the external calls. verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(1, CollectionUtils.size(businessObjectDataEntity.getAttributes())); BusinessObjectDataAttributeEntity result = IterableUtils.get(businessObjectDataEntity.getAttributes(), 0); assertEquals(ATTRIBUTE_NAME.toUpperCase(), result.getName()); assertEquals(ATTRIBUTE_VALUE_2, result.getValue()); }
@Test public void testRemovingAllWillNotRemoveLast() throws Exception { // setup Set<WiFiBand> values = EnumUtils.values(WiFiBand.class); // execute IterableUtils.forEach(values, new ToggleClosure()); // validate IterableUtils.forEachButLast(values, new RemovedClosure()); assertTrue(fixture.contains(IterableUtils.get(values, values.size() - 1))); }
@Test public void testUpdateGHZ5WithJapan() throws Exception { // setup when(settings.getCountryCode()).thenReturn(Locale.JAPAN.getCountry()); when(settings.getWiFiBand()).thenReturn(WiFiBand.GHZ5); when(settings.getSortBy()).thenReturn(SortBy.CHANNEL); // execute fixture.update(WiFiData.EMPTY); // validate verify(layout).setVisibility(View.VISIBLE); IterableUtils.forEach(views.keySet(), new PairClosure()); verify(settings).getCountryCode(); verify(settings, times(2)).getWiFiBand(); verify(settings).getSortBy(); }
@Test public void testGetBusinessObjectDataIncludeStorageUnitStatusHistory() { // Create a business object data key. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); // Create a business object data storage unit key. BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey = new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME); // Create a storage unit entity. StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, businessObjectDataKey, StorageUnitStatusEntity.DISABLED); // Execute a storage unit status change. businessObjectDataStorageUnitStatusService.updateBusinessObjectDataStorageUnitStatus(businessObjectDataStorageUnitKey, new BusinessObjectDataStorageUnitStatusUpdateRequest(StorageUnitStatusEntity.ENABLED)); // Retrieve the business object data with enabled include storage unit status history flag. BusinessObjectData resultBusinessObjectData = businessObjectDataService .getBusinessObjectData(businessObjectDataKey, PARTITION_KEY, NO_BDATA_STATUS, NO_INCLUDE_BUSINESS_OBJECT_DATA_STATUS_HISTORY, INCLUDE_STORAGE_UNIT_STATUS_HISTORY); // Build the expected response object. The storage unit history record is expected to have system username for the createdBy auditable field. BusinessObjectData expectedBusinessObjectData = new BusinessObjectData(storageUnitEntity.getBusinessObjectData().getId(), BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BDATA_STATUS, Arrays.asList( new StorageUnit(new Storage(STORAGE_NAME, StoragePlatformEntity.S3, null), NO_STORAGE_DIRECTORY, null, StorageUnitStatusEntity.ENABLED, Arrays .asList(new StorageUnitStatusChangeEvent(StorageUnitStatusEntity.ENABLED, HerdDateUtils.getXMLGregorianCalendarValue(IterableUtils.get(storageUnitEntity.getHistoricalStatuses(), 0).getCreatedOn()), HerdDaoSecurityHelper.SYSTEM_USER)), NO_STORAGE_POLICY_TRANSITION_FAILED_ATTEMPTS, NO_RESTORE_EXPIRATION_ON)), NO_ATTRIBUTES, NO_BUSINESS_OBJECT_DATA_PARENTS, NO_BUSINESS_OBJECT_DATA_CHILDREN, NO_BUSINESS_OBJECT_DATA_STATUS_HISTORY); // Validate the returned response object. assertEquals(expectedBusinessObjectData, resultBusinessObjectData); }
/** * Retrieves the parameter value from a list. * If the parameter has multiple definition, and so multiple values, the * first occurrence is returned. * * @param params The parameter list * @param name Parameter name * @param defaultValue Default value if the parameter is not defined * @return Parameter value or null is not present */ public static String getParameterValue(final List<Params> params, final String name, final String defaultValue) { Params tmpParam = IterableUtils.find( params, new Predicate<Params>() { @Override public boolean evaluate(final Params t) { return t.getName().equals(name); } }); if (tmpParam != null) { return tmpParam.getValue(); } return defaultValue; }
String getData(String timestamp, @NonNull List<WiFiDetail> wiFiDetails) { final StringBuilder result = new StringBuilder(); result.append( String.format(Locale.ENGLISH, "Time Stamp|SSID|BSSID|Strength|Primary Channel|Primary Frequency|Center Channel|Center Frequency|Width (Range)|Distance|Security%n")); IterableUtils.forEach(wiFiDetails, new WiFiDetailClosure(timestamp, result)); return result.toString(); }
@Test public void get_all_should_return_an_array_with_one_elem_with_page() { add_zone_twice_should_create_a_new_zone(); List<ZoneResource> zones = IterableUtils.toList(this.controller.getZones(infraId, new PageRequest(0, 1), new PagedResourcesAssembler<Zone>(resolver, null))); Assert.assertNotNull(zones); Assert.assertEquals(1, zones.size()); }
@Test public void delete_zone_should_work() { this.controller.deleteZone(infraId, id); List<ZoneResource> zones = IterableUtils.toList(this.controller.getZones(infraId, null, new PagedResourcesAssembler<Zone>(resolver, null))); Assert.assertNotNull(zones); Assert.assertEquals(0, zones.size()); }
@Test public void testRemoveExpectNoneLeft() throws Exception { // setup List<WiFiDetail> expected = withData(); // execute List<BaseSeries<DataPoint>> actual = fixture.remove(expected); // validate assertEquals(expected.size(), actual.size()); IterableUtils.forEach(expected, new ContainsFalseClosure()); }
@Test public void get_all_should_return_empty_array() { HttpEntity<PagedResources<AddressPlanResource>> resp = this.controller.getAddressPlans(infraId, null, new PagedResourcesAssembler<AddressPlan>(resolver, null)); Assert.assertNotNull(resp); Assert.assertNotNull(resp.getBody()); List<AddressPlanResource> plans = IterableUtils.toList(resp.getBody()); Assert.assertNotNull(plans); Assert.assertTrue(plans.isEmpty()); }
public WiFiChannel getWiFiChannelByFrequency(int frequency) { Pair<WiFiChannel, WiFiChannel> found = null; if (isInRange(frequency)) { found = IterableUtils.find(wiFiChannelPairs, new FrequencyPredicate(frequency)); } return found == null ? WiFiChannel.UNKNOWN : getWiFiChannel(frequency, found); }