Search in sources :

Example 1 with NamedProperty

use of org.summerb.properties.api.dto.NamedProperty in project summerb by skarpushin.

the class PropertyServiceImplTest method testPutSubjectProperties_whitebox_expectCorretPropertyNames.

@Test
public void testPutSubjectProperties_whitebox_expectCorretPropertyNames() throws Exception {
    List<NamedProperty> propList = new ArrayList<NamedProperty>();
    propList.add(new NamedProperty("some.property1", "value1"));
    propList.add(new NamedProperty("some.property2", "value2"));
    propertyService.putSubjectProperties("test", "test.domain", "1", propList);
    propertyService.putSubjectProperty("test", "test.domain", "2", "some.property1", "value3");
    Map<String, String> result = propertyService.findSubjectProperties("test", "test.domain", "1");
    assertTrue(result.containsKey("some.property1"));
    assertTrue(result.containsKey("some.property2"));
}
Also used : NamedProperty(org.summerb.properties.api.dto.NamedProperty) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with NamedProperty

use of org.summerb.properties.api.dto.NamedProperty in project summerb by skarpushin.

the class PropertyServiceImplTest method testPutProperty_expectTruncationExceptionForPropertyNameForMultipleProperties.

@Test
public void testPutProperty_expectTruncationExceptionForPropertyNameForMultipleProperties() {
    String propertyName = "some.property1";
    List<NamedProperty> props = new ArrayList<NamedProperty>();
    props.add(new NamedProperty("n1", "vvv1"));
    props.add(new NamedProperty(propertyName, generateLongString(256, "прол")));
    props.add(new NamedProperty("n2", "vvv2"));
    try {
        propertyService.putSubjectProperties("test", "test.domain", "AAA", props);
    } catch (Throwable t) {
        String foundName = DaoExceptionUtils.findTruncatedFieldNameIfAny(t);
        assertEquals(propertyName, foundName);
    }
}
Also used : NamedProperty(org.summerb.properties.api.dto.NamedProperty) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with NamedProperty

use of org.summerb.properties.api.dto.NamedProperty in project summerb by skarpushin.

the class PropertyServiceImpl method putSubjectProperties.

@Transactional(rollbackFor = Throwable.class)
@Override
public void putSubjectProperties(String appName, String domainName, String subjectId, List<NamedProperty> namedProperties) {
    if (CollectionUtils.isEmpty(namedProperties)) {
        return;
    }
    checkArgumentsHaveText(appName, domainName, subjectId);
    String currentPropertyName = null;
    try {
        long appId = appNameAlias.getAliasFor(appName);
        long domainId = domainNameAlias.getAliasFor(domainName);
        for (NamedProperty namedProperty : namedProperties) {
            currentPropertyName = namedProperty.getName();
            long propertyNameId = propertyNameAlias.getAliasFor(currentPropertyName);
            String value = namedProperty.getPropertyValue();
            propertyDao.putProperty(appId, domainId, subjectId, propertyNameId, value);
        }
    } catch (Throwable t) {
        propagatePropertyNameIfTruncationError(t, currentPropertyName);
        throw new PropertyServiceUnexpectedException("Failed to put subject properties", t);
    }
}
Also used : NamedProperty(org.summerb.properties.api.dto.NamedProperty) PropertyServiceUnexpectedException(org.summerb.properties.api.exceptions.PropertyServiceUnexpectedException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

NamedProperty (org.summerb.properties.api.dto.NamedProperty)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Transactional (org.springframework.transaction.annotation.Transactional)1 PropertyServiceUnexpectedException (org.summerb.properties.api.exceptions.PropertyServiceUnexpectedException)1