Search in sources :

Example 1 with PMMLListener

use of org.kie.pmml.api.runtime.PMMLListener in project drools by kiegroup.

the class PMMLRuntimeInternalImplTest method addPMMLListener.

@Test
public void addPMMLListener() {
    try {
        pmmlRuntime.evaluate(MODEL_NAME, pmmlContextMock);
        verify(pmmlContextMock, never()).addPMMLListener(any());
    } catch (KiePMMLException e) {
        commonManageException(e);
    }
    try {
        reset(pmmlContextMock);
        PMMLListener listener = getPMMLListener(new ArrayList<>());
        pmmlRuntime.addPMMLListener(listener);
        pmmlRuntime.evaluate(MODEL_NAME, pmmlContextMock);
        verify(pmmlContextMock).addPMMLListener(listener);
    } catch (KiePMMLException e) {
        commonManageException(e);
    }
}
Also used : KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) PMMLListener(org.kie.pmml.api.runtime.PMMLListener) Test(org.junit.Test)

Example 2 with PMMLListener

use of org.kie.pmml.api.runtime.PMMLListener in project drools by kiegroup.

the class PMMLRuntimeInternalImplTest method removePMMLListener.

@Test
public void removePMMLListener() {
    try {
        PMMLListener listener = getPMMLListener(new ArrayList<>());
        pmmlRuntime.addPMMLListener(listener);
        pmmlRuntime.removePMMLListener(listener);
        pmmlRuntime.evaluate("MODEL_NAME", pmmlContextMock);
        verify(pmmlContextMock, never()).addPMMLListener(listener);
    } catch (KiePMMLException e) {
        commonManageException(e);
    }
}
Also used : KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) PMMLListener(org.kie.pmml.api.runtime.PMMLListener) Test(org.junit.Test)

Example 3 with PMMLListener

use of org.kie.pmml.api.runtime.PMMLListener in project drools by kiegroup.

the class PMMLMiningModelEvaluatorTest method addStep.

@Test
public void addStep() {
    PMMLStep step = mock(PMMLStep.class);
    Set<PMMLListener> pmmlListenersMock = IntStream.range(0, 3).mapToObj(i -> mock(PMMLListener.class)).collect(Collectors.toSet());
    PMMLContext pmmlContextMock = mock(PMMLContext.class);
    when(pmmlContextMock.getPMMLListeners()).thenReturn(pmmlListenersMock);
    evaluator.addStep(() -> step, pmmlContextMock);
    pmmlListenersMock.forEach(pmmlListenerMock -> verify(pmmlListenerMock).stepExecuted(step));
}
Also used : MAX(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.MAX) Arrays(java.util.Arrays) WEIGHTED_AVERAGE(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.WEIGHTED_AVERAGE) SELECT_ALL(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.SELECT_ALL) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) PMML_MODEL(org.kie.pmml.api.enums.PMML_MODEL) WEIGHTED_MAJORITY_VOTE(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.WEIGHTED_MAJORITY_VOTE) PMMLRuntimeInternal(org.kie.pmml.evaluator.api.executor.PMMLRuntimeInternal) Map(java.util.Map) PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest) Assert.fail(org.junit.Assert.fail) MINING_FUNCTION(org.kie.pmml.api.enums.MINING_FUNCTION) KiePMMLValueWeight(org.kie.pmml.commons.model.tuples.KiePMMLValueWeight) ResultCode(org.kie.pmml.api.enums.ResultCode) MAJORITY_VOTE(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.MAJORITY_VOTE) Set(java.util.Set) Collectors(java.util.stream.Collectors) AVERAGE(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.AVERAGE) PMMLContext(org.kie.pmml.api.runtime.PMMLContext) List(java.util.List) KiePMMLTestingModel(org.kie.pmml.commons.testingutility.KiePMMLTestingModel) Assert.assertFalse(org.junit.Assert.assertFalse) WEIGHTED_MEDIAN(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.WEIGHTED_MEDIAN) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) OK(org.kie.pmml.api.enums.ResultCode.OK) PMMLRuntime(org.kie.pmml.api.runtime.PMMLRuntime) PMML4Result(org.kie.api.pmml.PMML4Result) MULTIPLE_MODEL_METHOD(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) KiePMMLMiningModel(org.kie.pmml.models.mining.model.KiePMMLMiningModel) MEDIAN(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.MEDIAN) KiePMMLInternalException(org.kie.pmml.api.exceptions.KiePMMLInternalException) KieServices(org.kie.api.KieServices) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) KieBase(org.kie.api.KieBase) Before(org.junit.Before) KiePMMLSegment(org.kie.pmml.models.mining.model.segmentation.KiePMMLSegment) WEIGHTED_SUM(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.WEIGHTED_SUM) FAIL(org.kie.pmml.api.enums.ResultCode.FAIL) Assert.assertNotNull(org.junit.Assert.assertNotNull) SUM(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.SUM) KieContainer(org.kie.api.runtime.KieContainer) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) SELECT_FIRST(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.SELECT_FIRST) Mockito.verify(org.mockito.Mockito.verify) MODEL_CHAIN(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.MODEL_CHAIN) Assert.assertNull(org.junit.Assert.assertNull) PMMLListener(org.kie.pmml.api.runtime.PMMLListener) KiePMMLModelException(org.kie.pmml.evaluator.api.exceptions.KiePMMLModelException) KiePMMLSegmentation(org.kie.pmml.models.mining.model.segmentation.KiePMMLSegmentation) Collections(java.util.Collections) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) PMMLStep(org.kie.pmml.api.models.PMMLStep) Assert.assertEquals(org.junit.Assert.assertEquals) PMMLStep(org.kie.pmml.api.models.PMMLStep) PMMLListener(org.kie.pmml.api.runtime.PMMLListener) PMMLContext(org.kie.pmml.api.runtime.PMMLContext) PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)3 PMMLListener (org.kie.pmml.api.runtime.PMMLListener)3 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertNotEquals (org.junit.Assert.assertNotEquals)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Assert.assertNull (org.junit.Assert.assertNull)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Assert.fail (org.junit.Assert.fail)1 Before (org.junit.Before)1