Package gov.nasa.arc.mct.evaluator.api

Examples of gov.nasa.arc.mct.evaluator.api.Executor


 
  @SuppressWarnings("unchecked")
  @Test(dataProvider="evalTestData")
  public void testEvalutor(String code, String inputValue, String expectedValue) {
    EnumEvaluator enumEvaluator = new EnumEvaluator();
    Executor e = enumEvaluator.compile(code);
    FeedProvider fp = Mockito.mock(FeedProvider.class);
    Mockito.when(fp.getSubscriptionId()).thenReturn("abc");
    FeedProvider.RenderingInfo data = new FeedProvider.RenderingInfo(inputValue, Color.red, "x", Color.red, true);
    Mockito.when(fp.getRenderingInfo(Mockito.anyMap())).thenReturn(data);
    Map<String, String> value = Collections.singletonMap(FeedProvider.NORMALIZED_RENDERING_INFO, data.toString());
    List<Map<String, String>> values = Collections.singletonList(value);
    Map<String, List<Map<String, String>>> dataSet = Collections.singletonMap(fp.getSubscriptionId(), values);
    FeedProvider.RenderingInfo info = e.evaluate(dataSet, Collections.singletonList(fp));
    Assert.assertTrue(info.isValid());
    Assert.assertEquals(info.getValueText(), expectedValue);
  }
View Full Code Here


        }
      });

      providers.add(provider);
    }
    Executor executor = evaluator.compile(expression);
    FeedProvider.RenderingInfo ri = executor.evaluate(data, providers);
    Assert.assertEquals(ri.getValueText(), expectedValue);
//    Assert.assertEquals(ri.getStatusText(), expectedStatus);
//    Assert.assertEquals(ri.isValid(), isValid);
  }
View Full Code Here

        }
      });

      providers.add(provider);
    }
    Executor executor = evaluator.compile(expression);
    FeedProvider.RenderingInfo ri = executor.evaluate(data, providers);
    Assert.assertEquals(ri, expectedValue);
//    Assert.assertEquals(ri.getStatusText(), expectedStatus);
//    Assert.assertEquals(ri.isValid(), isValid);
  }
View Full Code Here

    final FeedProvider.RenderingInfo expectedRenderingInfo = new FeedProvider.RenderingInfo("", Color.black, "", Color.black, false);
   
    EvaluatorProvider ep = Mockito.mock(EvaluatorProvider.class);
    e = ec.getCapability(Evaluator.class);
    registry.addProvider(ep);
    Executor executor = Mockito.mock(Executor.class);
    Mockito.when(executor.evaluate(Mockito.anyMap(), Mockito.anyList())).thenReturn(expectedRenderingInfo);
    Mockito.when(ep.getLanguage()).thenReturn(language);
    Mockito.when(ep.compile(Mockito.anyString())).thenReturn(executor);
   
    Assert.assertSame(expectedRenderingInfo, e.evaluate(Collections.<String,List<Map<String,String>>>emptyMap(), Collections.<FeedProvider>emptyList()));
  }
View Full Code Here

    final FeedProvider.RenderingInfo expectedRenderingInfo = new FeedProvider.RenderingInfo("", Color.white, "", Color.white, false);
   
    MultiProvider mp = Mockito.mock(MultiProvider.class);
    e = mc.getCapability(Evaluator.class);
    registry.addProvider(mp);
    Executor executor = Mockito.mock(Executor.class);
    Mockito.when(executor.evaluate(Mockito.anyMap(), Mockito.anyList())).thenReturn(expectedRenderingInfo);
    Mockito.when(mp.getLanguage()).thenReturn(language);
    Mockito.when(mp.compile(Mockito.anyString())).thenReturn(executor);
   
    Assert.assertSame(expectedRenderingInfo, e.evaluate(Collections.<String,List<Map<String,String>>>emptyMap(), Collections.<FeedProvider>emptyList()));
  }
View Full Code Here

    Mockito.when(evaluatorProvider.getLanguage()).thenReturn(language);
    Mockito.when(mockData.getLanguage()).thenReturn(language);
    Mockito.when(evaluatorProvider.compile(Mockito.anyString())).thenReturn(new ReturnExecutor())
    new EvaluatorProviderRegistry().addProvider(evaluatorProvider);
   
    final Executor executor =
      EvaluatorProviderRegistry.getExecutor(EvaluatorComponent.class.cast(parentComponent));
   
    final Evaluator e = new Evaluator() {

      @Override
      public String getCode() {
        return "test";
      }

      @Override
      public String getDisplayName() {
        return "testName";
      }

      @Override
      public String getLanguage() {
        return language;
      }
     
      public boolean requiresMultipleInputs() {
        return false;
      }

      @Override
      public FeedProvider.RenderingInfo evaluate(Map<String, List<Map<String, String>>> data,
          List<FeedProvider> providers) {
        return executor.evaluate(data, providers);
      }
     
    };
   
    final Evaluator e2 = new Evaluator() {

      @Override
      public String getCode() {
        return "test2";
      }

      @Override
      public String getDisplayName() {
        return "testName2";
      }

      @Override
      public String getLanguage() {
        return language;
      }
     
      public boolean requiresMultipleInputs() {
        return false;
      }

      @Override
      public FeedProvider.RenderingInfo evaluate(Map<String, List<Map<String, String>>> data,
          List<FeedProvider> providers) {
        return executor.evaluate(data, providers);
      }
     
    };

    eList = new ArrayList<Evaluator>();
View Full Code Here

        public boolean requiresMultipleInputs() {
          return getExecutor() != null && getExecutor().requiresMultipleInputs();
        }

        private Executor getExecutor() {
          Executor e = executor.get();
          if (e == null) {
            executor.set(e = MultiProviderRegistry.getExecutor(MultiComponent.this));
          }
         
          return e;
        }
       
        private final AtomicReference<Executor> executor = new AtomicReference<Executor>();
       
        @Override
        public FeedProvider.RenderingInfo evaluate(
            Map<String, List<Map<String, String>>> data,
            List<FeedProvider> providers) {
          Executor e = getExecutor();
         
          FeedProvider.RenderingInfo ri = null;
          if (e != null) {
            if (getData().isPassThrough()) {
              for (FeedProvider fp : providers) {
                if (fp.getSubscriptionId().equals(getData().getPassThroughParameterId())) {
                  List<Map<String,String>> values = data.get(getData().getPassThroughParameterId());
                  if (values != null && !values.isEmpty()) {
                    ri = fp.getRenderingInfo(values.get(values.size() - 1));
                  }
                }
              }
            } else {
              ri = e.evaluate(data, providers);
              if (ri == null) {
                ri = new FeedProvider.RenderingInfo(getData().getFallThroughDisplayValue(), Color.red, "", Color.red, false);
              }
            }
          } else {
View Full Code Here

  // this is not a traditional singleton as this class is created by the OSGi declarative services mechanism.
 
  public static Executor getExecutor(MultiComponent component) {
    MultiData data = component.getData();
    String language = data.getLanguage();
    Executor executor = null;
    // cache here if necessary
    for (MultiProvider provider : registry) {
      if (provider.getLanguage().equals(language)) {
        executor = provider.compile(data.getCode());
        break;
View Full Code Here

  // this is not a traditional singleton as this class is created by the OSGi declarative services mechanism.
 
  public static Executor getExecutor(EvaluatorComponent component) {
    EvaluatorData data = component.getData();
    String language = data.getLanguage();
    Executor executor = null;
    // cache here if necessary
    for (EvaluatorProvider provider : registry) {
      if (provider.getLanguage().equals(language)) {
        executor = provider.compile(data.getCode());
        break;
View Full Code Here

        public boolean requiresMultipleInputs() {
          return getExecutor() != null && getExecutor().requiresMultipleInputs();
        }

        private Executor getExecutor() {
          Executor e = executor.get();
          if (e == null) {
            executor.set(e = EvaluatorProviderRegistry.getExecutor(EvaluatorComponent.this));
          }
         
          return e;
        }
       
        private final AtomicReference<Executor> executor = new AtomicReference<Executor>();
       
        @Override
        public FeedProvider.RenderingInfo evaluate(
            Map<String, List<Map<String, String>>> data,
            List<FeedProvider> providers) {
          Executor e = getExecutor();
         
          FeedProvider.RenderingInfo ri;
          if (e != null) {
            ri = e.evaluate(data, providers);
          } else {
            LoggerFactory.getLogger(EvaluatorComponent.class).error("no evaluator provider available for " + getLanguage());
            ri = new FeedProvider.RenderingInfo("", Color.red, "", Color.red,false);
          }
         
View Full Code Here

TOP

Related Classes of gov.nasa.arc.mct.evaluator.api.Executor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.