GraphOp extends Operator { private OperatorContext getOperatorContext() { OperatorContext operatorContext; try { Field field = Operator.class.getDeclaredField("context"); field.setAccessible(true); operatorContext = (OperatorContext) field.get(this); field.setAccessible(false); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } catch (NoSuchFieldException e) { throw new IllegalStateException(e); } return operatorContext; }  @Override void initialize();  }
@Test public void testParameterValuesAreUsedFromHeader() throws Exception { Map<String, Product> sourceProducts = new HashMap<String, Product>(1); Product testProduct = new Product("p", "t", 1, 1); testProduct.addBand("Op1A", ProductData.TYPE_INT8); sourceProducts.put("toa", testProduct); Product targetProduct = GPF.createProduct("Op2Graph", new HashMap<String, Object>(), sourceProducts); assertNotNull(targetProduct); assertEquals("Op2Name", targetProduct.getName()); OperatorProductReader operatorProductReader = (OperatorProductReader) targetProduct.getProductReader(); Operator operator = operatorProductReader.getOperatorContext().getOperator(); TestOps.Op2 op2 = (Op2) operator; assertEquals(24.0, op2.threshold, 0.00001); }
@Test public void testOneNodeDirectCall() throws Exception { Map<String, Object> parameters = new HashMap<String, Object>(1); parameters.put("THR", 65.0); Map<String, Product> sourceProducts = new HashMap<String, Product>(1); Product testProduct = new Product("p", "t", 1, 1); testProduct.addBand("Op1A", ProductData.TYPE_INT8); sourceProducts.put("toa", testProduct); Product targetProduct = GPF.createProduct("Op2Graph", parameters, sourceProducts); assertNotNull(targetProduct); assertEquals("Op2Name", targetProduct.getName()); OperatorProductReader operatorProductReader = (OperatorProductReader) targetProduct.getProductReader(); Operator operator = operatorProductReader.getOperatorContext().getOperator(); TestOps.Op2 op2 = (Op2) operator; assertEquals(65.0, op2.threshold, 0.00001); }
@Test public void testTwoNodesDirectCall() throws Exception { Map<String, Object> parameters = new HashMap<String, Object>(1); parameters.put("THR", 66.0); Product targetProduct = GPF.createProduct("SourcelessOp1Op2Graph", parameters, Collections.EMPTY_MAP); assertNotNull(targetProduct); assertEquals("Op2Name", targetProduct.getName()); OperatorProductReader operatorProductReader = (OperatorProductReader) targetProduct.getProductReader(); Operator operator = operatorProductReader.getOperatorContext().getOperator(); TestOps.Op2 op2 = (Op2) operator; assertEquals(66.0, op2.threshold, 0.00001); }
@Test public void testUsesOtherGraph() throws Exception { Map<String, Object> parameters = new HashMap<String, Object>(1); parameters.put("THR", 67.0); Product targetProduct = GPF.createProduct("UsesOtherGraph", parameters, Collections.EMPTY_MAP); assertNotNull(targetProduct); assertEquals("Op2Name", targetProduct.getName()); OperatorProductReader operatorProductReader = (OperatorProductReader) targetProduct.getProductReader(); Operator operator = operatorProductReader.getOperatorContext().getOperator(); TestOps.Op2 op2 = (Op2) operator; assertEquals(67.0, op2.threshold, 0.00001); }