Search in sources :

Example 16 with Arrays.asList

use of java.util.Arrays.asList in project motech by motech.

the class LookupProcessorTest method shouldProcessMethodWithLookupFields.

@Test
public void shouldProcessMethodWithLookupFields() throws NoSuchMethodException {
    FieldDto arg1Field = new FieldDto("arg1", "Arg1", TypeDto.INTEGER);
    FieldDto secondArgumentField = new FieldDto("secondArgument", "Second Argument", TypeDto.STRING);
    lookupProcessor.setEntityProcessingResult(Arrays.asList(mockEntityProcessorOutput(new EntityDto(TestClass.class.getName()), Arrays.asList(arg1Field, secondArgumentField))));
    when(paranamer.lookupParameterNames(getTestMethod(1))).thenReturn(argNames);
    Method method = getTestMethod(1);
    lookupProcessor.process(method);
    Map<String, List<LookupDto>> elements = lookupProcessor.getProcessingResult();
    assertTrue(elements.containsKey(TEST_CLASS_NAME));
    List<LookupDto> list = elements.get(TEST_CLASS_NAME);
    LookupDto expected = new LookupDto("Test Method 1", true, false, asList(lookupFieldDto("arg1"), lookupFieldDto("secondArgument", "LIKE")), true, "testMethod1", asList("arg1", "secondArgument"), true);
    assertEquals(1, list.size());
    assertEquals(expected, list.get(0));
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) LookupDto(org.motechproject.mds.dto.LookupDto) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Method(java.lang.reflect.Method) FieldTestHelper.lookupFieldDto(org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) Test(org.junit.Test)

Example 17 with Arrays.asList

use of java.util.Arrays.asList in project motech by motech.

the class LookupProcessorTest method shouldNotCreateIndexForLookup.

@Test
public void shouldNotCreateIndexForLookup() throws Exception {
    FieldDto arg1Field = new FieldDto("arg1", "Arg1", TypeDto.INTEGER);
    FieldDto secondArgumentField = new FieldDto("secondArgument", "Second Argument", TypeDto.STRING);
    lookupProcessor.setEntityProcessingResult(Arrays.asList(mockEntityProcessorOutput(new EntityDto(TestClass.class.getName()), Arrays.asList(arg1Field, secondArgumentField))));
    when(paranamer.lookupParameterNames(getTestMethod(5))).thenReturn(argNames);
    Method method = getTestMethod(5);
    lookupProcessor.process(method);
    Map<String, List<LookupDto>> elements = lookupProcessor.getProcessingResult();
    assertTrue(elements.containsKey(TEST_CLASS_NAME));
    List<LookupDto> list = elements.get(TEST_CLASS_NAME);
    LookupDto expected = new LookupDto("Test Method 5", true, false, asList(lookupFieldDto("arg1"), lookupFieldDto("secondArgument", "LIKE")), true, "testMethod5", new ArrayList<>(), false);
    assertEquals(1, list.size());
    assertEquals(expected, list.get(0));
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) LookupDto(org.motechproject.mds.dto.LookupDto) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Method(java.lang.reflect.Method) FieldTestHelper.lookupFieldDto(org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) Test(org.junit.Test)

Example 18 with Arrays.asList

use of java.util.Arrays.asList in project motech by motech.

the class LookupProcessorTest method shouldProcessMethodWithSetParam.

@Test
public void shouldProcessMethodWithSetParam() throws NoSuchMethodException {
    FieldDto arg0Field = new FieldDto("arg0Field", "Arg 0 Field", TypeDto.STRING);
    FieldDto setField = new FieldDto("setField", "Range Field", TypeDto.STRING);
    FieldDto regularField = new FieldDto("regularField", "Regular Field", TypeDto.STRING);
    FieldDto setFieldDouble = new FieldDto("setFieldDouble", "Set Field", TypeDto.DOUBLE);
    EntityProcessorOutput eop = mockEntityProcessorOutput(new EntityDto(TestClass.class.getName()), Arrays.asList(arg0Field, setField, regularField, setFieldDouble));
    lookupProcessor.setEntityProcessingResult(Arrays.asList(eop));
    LookupFieldDto[][] expectedFields = { { lookupFieldDto("arg0"), lookupFieldDto("set", SET) }, { lookupFieldDto("regularField"), lookupFieldDto("setField", SET) } };
    String[][] expectedFieldsOrder = { { "arg0", "range" }, { "regularField", "rangeField" } };
    // test two methods, one with @LookupField annotations, second without
    for (int i = 0; i < 2; i++) {
        Method method = getTestMethodWithSetParam(i);
        when(paranamer.lookupParameterNames(method)).thenReturn(new String[] { "arg0", "set" });
        LookupDto expectedLookup = new LookupDto("Test Method With Set Param " + i, true, false, asList(expectedFields[i]), true, "testMethodWithSetParam" + i, asList(expectedFieldsOrder[i]), true);
        lookupProcessor.process(method);
        Map<String, List<LookupDto>> elements = lookupProcessor.getProcessingResult();
        assertTrue(elements.containsKey(TEST_CLASS_NAME));
        List<LookupDto> list = elements.get(TEST_CLASS_NAME);
        assertEquals(1, list.size());
        assertEquals(expectedLookup, list.get(0));
        assertEquals(asList(VALUE, SET), extract(list.get(0).getLookupFields(), on(LookupFieldDto.class).getType()));
        lookupProcessor.clear();
    }
}
Also used : LookupDto(org.motechproject.mds.dto.LookupDto) Method(java.lang.reflect.Method) EntityDto(org.motechproject.mds.dto.EntityDto) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) FieldTestHelper.lookupFieldDto(org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) Test(org.junit.Test)

Example 19 with Arrays.asList

use of java.util.Arrays.asList in project jnosql-diana-driver by eclipse.

the class ArangoDBDocumentCollectionManagerTest method shouldSaveSubDocument2.

@Test
public void shouldSaveSubDocument2() {
    DocumentEntity entity = getEntity();
    entity.add(Document.of("phones", Arrays.asList(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231"))));
    DocumentEntity entitySaved = entityManager.insert(entity);
    Document id = entitySaved.find(KEY_NAME).get();
    DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
    DocumentEntity entityFound = entityManager.select(query).get(0);
    Document subDocument = entityFound.find("phones").get();
    List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
    });
    assertThat(documents, containsInAnyOrder(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231")));
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) ArrayList(java.util.ArrayList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Example 20 with Arrays.asList

use of java.util.Arrays.asList in project kafka by apache.

the class MemoryRecordsTest method testUnsupportedCompress.

@Test
public void testUnsupportedCompress() {
    BiFunction<Byte, CompressionType, MemoryRecords> builderBiFunction = (magic, compressionType) -> MemoryRecords.withRecords(magic, compressionType, new SimpleRecord(10L, "key1".getBytes(), "value1".getBytes()));
    Arrays.asList(MAGIC_VALUE_V0, MAGIC_VALUE_V1).forEach(magic -> {
        Exception e = assertThrows(IllegalArgumentException.class, () -> builderBiFunction.apply(magic, CompressionType.ZSTD));
        assertEquals(e.getMessage(), "ZStandard compression is not supported for magic " + magic);
    });
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) MAGIC_VALUE_V2(org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V2) MAGIC_VALUE_V1(org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V1) BiFunction(java.util.function.BiFunction) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) MAGIC_VALUE_V0(org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V0) Supplier(java.util.function.Supplier) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) OptionalLong(java.util.OptionalLong) RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BufferSupplier(org.apache.kafka.common.utils.BufferSupplier) RecordFilter(org.apache.kafka.common.record.MemoryRecords.RecordFilter) Arrays.asList(java.util.Arrays.asList) ArgumentsProvider(org.junit.jupiter.params.provider.ArgumentsProvider) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) LeaderChangeMessage(org.apache.kafka.common.message.LeaderChangeMessage) Utils(org.apache.kafka.common.utils.Utils) TopicPartition(org.apache.kafka.common.TopicPartition) TestUtils(org.apache.kafka.test.TestUtils) Voter(org.apache.kafka.common.message.LeaderChangeMessage.Voter) Arguments(org.junit.jupiter.params.provider.Arguments) CloseableIterator(org.apache.kafka.common.utils.CloseableIterator) Test(org.junit.jupiter.api.Test) BatchRetention(org.apache.kafka.common.record.MemoryRecords.RecordFilter.BatchRetention) CorruptRecordException(org.apache.kafka.common.errors.CorruptRecordException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource) Collections(java.util.Collections) CorruptRecordException(org.apache.kafka.common.errors.CorruptRecordException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Arrays.asList (java.util.Arrays.asList)73 List (java.util.List)66 ArrayList (java.util.ArrayList)49 Test (org.junit.Test)37 Arrays (java.util.Arrays)22 Collections.singletonList (java.util.Collections.singletonList)20 Map (java.util.Map)18 Collectors (java.util.stream.Collectors)18 Test (org.junit.jupiter.api.Test)15 HashMap (java.util.HashMap)14 Before (org.junit.Before)13 Collection (java.util.Collection)12 Stream (java.util.stream.Stream)10 Method (java.lang.reflect.Method)9 Optional (java.util.Optional)9 Collections (java.util.Collections)8 Collections.emptyList (java.util.Collections.emptyList)8 TopicPartition (org.apache.kafka.common.TopicPartition)8 Employee (com.artezio.arttime.datamodel.Employee)6 HourType (com.artezio.arttime.datamodel.HourType)6