src_fm_fc_ms_ff
stringlengths
43
86.8k
target
stringlengths
20
276k
ResultsDeserializer implements ObjectDeserializer { @Override public Object deserialize(JsonNode n, ObjectMapper mapper) { Object o = null; try { if (n.has("payload")) { o = parent.deserialize(n.get("payload"), mapper); } } catch (Exception e) { logger.error("exception deserializing Results ", e); } return o; } ResultsDeserializer(BeakerObjectConverter p); @Override boolean canBeUsed(JsonNode n); @Override Object deserialize(JsonNode n, ObjectMapper mapper); }
@Test public void deserialize_resultObjectHasPayload() throws Exception { boolean payload = true; ObjectMapper mapper = new ObjectMapper(); JsonNode actualObj = mapper.readTree( "{\"type\":\"Results\",\"payload\":\"" + payload + "\"}"); ResultsDeserializer deserializer = new ResultsDeserializer(new BasicObjectSerializer()); Boolean result = (Boolean) deserializer.deserialize(actualObj, mapper); Assertions.assertThat(result).isEqualTo(payload); }
MapDeserializer implements ObjectDeserializer { @Override public Object deserialize(JsonNode n, ObjectMapper mapper) { HashMap<String, Object> o = new HashMap<String,Object>(); try { logger.debug("using custom map deserializer"); Iterator<Entry<String, JsonNode>> e = n.fields(); while(e.hasNext()) { Entry<String, JsonNode> ee = e.next(); o.put(ee.getKey(), parent.deserialize(ee.getValue(),mapper)); } } catch (Exception e) { logger.error("exception deserializing Map ", e); o = null; } return o; } MapDeserializer(BeakerObjectConverter p); @Override boolean canBeUsed(JsonNode n); @Override Object deserialize(JsonNode n, ObjectMapper mapper); }
@Test public void deserialize_resultObjectHasValues() throws Exception { ObjectMapper mapper = new ObjectMapper(); JsonNode actualObj = mapper.readTree("{\"k1\":\"1\",\"k2\":\"true\"}"); MapDeserializer deserializer = new MapDeserializer(new BasicObjectSerializer()); Map map = (Map) deserializer.deserialize(actualObj, mapper); Assertions.assertThat(map).isNotNull(); Assertions.assertThat(map.get("k2")).isEqualTo(true); }
DateDeserializer implements ObjectDeserializer { @Override public Object deserialize(JsonNode n, ObjectMapper mapper) { Object o = null; try { if (n.has("timestamp")) o = new Date(n.get("timestamp").asLong()); } catch (Exception e) { logger.error("exception deserializing Date {}", e.getMessage()); } return o; } DateDeserializer(BeakerObjectConverter p); @Override boolean canBeUsed(JsonNode n); @Override Object deserialize(JsonNode n, ObjectMapper mapper); }
@Test public void deserialize_resultObjectHasTimestamp() throws Exception { long timestamp = 1492423972082L; ObjectMapper mapper = new ObjectMapper(); JsonNode actualObj = mapper.readTree("{\"type\":\"Date\",\"timestamp\":"+ timestamp +"}"); DateDeserializer deserializer = new DateDeserializer(new BasicObjectSerializer()); Date date = (Date) deserializer.deserialize(actualObj, mapper); Assertions.assertThat(date).isNotNull(); Assertions.assertThat(date.getTime()).isEqualTo(timestamp); }
BasicObjectSerializer implements BeakerObjectConverter { protected boolean isPrimitiveTypeMap(Object o) { if (!(o instanceof Map<?, ?>)) return false; Map<?, ?> m = (Map<?, ?>) o; Set<?> eset = m.entrySet(); for (Object entry : eset) { Entry<?, ?> e = (Entry<?, ?>) entry; if (e.getValue() != null && !isPrimitiveType(e.getValue().getClass().getName())) return false; } return true; } BasicObjectSerializer(); @Override String convertType(String tn); @Override boolean isPrimitiveType(String tn); @Override boolean writeObject(Object obj, JsonGenerator jgen, boolean expand); boolean runThreadSerializers(Object obj, JsonGenerator jgen, boolean expand); boolean runConfiguredSerializers(Object obj, JsonGenerator jgen, boolean expand); @Override Object deserialize(JsonNode n, ObjectMapper mapper); @Override void addTypeConversion(String from, String to); @Override void addTypeDeserializer(ObjectDeserializer o); @Override void addTypeSerializer(ObjectSerializer o); @Override void addfTypeDeserializer(ObjectDeserializer o); @Override void addfTypeSerializer(ObjectSerializer o); @Override void addThreadSpecificTypeConversion(String from, String to); @Override void addThreadSpecificTypeDeserializer(ObjectDeserializer o); @Override void addThreadSpecificTypeSerializer(ObjectSerializer o); @Override void addKnownBeakerType(String t); @Override boolean isKnownBeakerType(String t); static final String TYPE_INTEGER; static final String TYPE_LONG; static final String TYPE_BIGINT; static final String TYPE_DOUBLE; static final String TYPE_STRING; static final String TYPE_BOOLEAN; static final String TYPE_TIME; static final String TYPE_SELECT; }
@Test public void isPrimitiveTypeMap_returnTrue() throws Exception { Map<String, String> map = new HashMap<String, String>(){ { put("key", "value"); } }; boolean result = basicObjectSerializer.isPrimitiveTypeMap(map); Assertions.assertThat(result).isTrue(); }
BasicObjectSerializer implements BeakerObjectConverter { protected boolean isListOfPrimitiveTypeMaps(Object o) { if (!(o instanceof Collection<?>)) return false; Collection<?> c = (Collection<?>) o; if (c.isEmpty()) return false; for (Object obj : c) { if (obj != null && !isPrimitiveTypeMap(obj)) { return false; } } return true; } BasicObjectSerializer(); @Override String convertType(String tn); @Override boolean isPrimitiveType(String tn); @Override boolean writeObject(Object obj, JsonGenerator jgen, boolean expand); boolean runThreadSerializers(Object obj, JsonGenerator jgen, boolean expand); boolean runConfiguredSerializers(Object obj, JsonGenerator jgen, boolean expand); @Override Object deserialize(JsonNode n, ObjectMapper mapper); @Override void addTypeConversion(String from, String to); @Override void addTypeDeserializer(ObjectDeserializer o); @Override void addTypeSerializer(ObjectSerializer o); @Override void addfTypeDeserializer(ObjectDeserializer o); @Override void addfTypeSerializer(ObjectSerializer o); @Override void addThreadSpecificTypeConversion(String from, String to); @Override void addThreadSpecificTypeDeserializer(ObjectDeserializer o); @Override void addThreadSpecificTypeSerializer(ObjectSerializer o); @Override void addKnownBeakerType(String t); @Override boolean isKnownBeakerType(String t); static final String TYPE_INTEGER; static final String TYPE_LONG; static final String TYPE_BIGINT; static final String TYPE_DOUBLE; static final String TYPE_STRING; static final String TYPE_BOOLEAN; static final String TYPE_TIME; static final String TYPE_SELECT; }
@Test public void isListOfPrimitiveTypeMaps_returnTrue() throws Exception { boolean result = basicObjectSerializer.isListOfPrimitiveTypeMaps( ObservableTableDisplayTest.getListOfMapsData()); Assertions.assertThat(result).isTrue(); }
BasicObjectSerializer implements BeakerObjectConverter { protected boolean isPrimitiveTypeListOfList(Object o) { if (!(o instanceof Collection<?>)) return false; Collection<?> m = (Collection<?>) o; int max = 0; for (Object entry : m) { if (!(entry instanceof Collection<?>)) return false; Collection<?> e = (Collection<?>) entry; for (Object ei : e) { if (ei != null && !isPrimitiveType(ei.getClass().getName())) return false; } if (max < e.size()) max = e.size(); } return max >= 2 && m.size() >= 2; } BasicObjectSerializer(); @Override String convertType(String tn); @Override boolean isPrimitiveType(String tn); @Override boolean writeObject(Object obj, JsonGenerator jgen, boolean expand); boolean runThreadSerializers(Object obj, JsonGenerator jgen, boolean expand); boolean runConfiguredSerializers(Object obj, JsonGenerator jgen, boolean expand); @Override Object deserialize(JsonNode n, ObjectMapper mapper); @Override void addTypeConversion(String from, String to); @Override void addTypeDeserializer(ObjectDeserializer o); @Override void addTypeSerializer(ObjectSerializer o); @Override void addfTypeDeserializer(ObjectDeserializer o); @Override void addfTypeSerializer(ObjectSerializer o); @Override void addThreadSpecificTypeConversion(String from, String to); @Override void addThreadSpecificTypeDeserializer(ObjectDeserializer o); @Override void addThreadSpecificTypeSerializer(ObjectSerializer o); @Override void addKnownBeakerType(String t); @Override boolean isKnownBeakerType(String t); static final String TYPE_INTEGER; static final String TYPE_LONG; static final String TYPE_BIGINT; static final String TYPE_DOUBLE; static final String TYPE_STRING; static final String TYPE_BOOLEAN; static final String TYPE_TIME; static final String TYPE_SELECT; }
@Test public void isPrimitiveTypeListOfList_returnTrue() throws Exception { boolean result = basicObjectSerializer.isPrimitiveTypeListOfList( Arrays.asList(Arrays.asList("k1", 1), Arrays.asList("k2", 2))); Assertions.assertThat(result).isTrue(); }
BasicObjectSerializer implements BeakerObjectConverter { @Override public boolean writeObject(Object obj, JsonGenerator jgen, boolean expand) throws IOException { if (obj == null) { jgen.writeNull(); } else if ((obj instanceof TableDisplay) || (obj instanceof EvaluationResult) || (obj instanceof UpdatableEvaluationResult) || (obj instanceof BeakerCodeCell) || (obj instanceof ImageIcon) || (obj instanceof Date) || (obj instanceof BeakerDashboard) || (obj instanceof BufferedImage) || (obj instanceof TabbedOutputContainerLayoutManager) || (obj instanceof GridOutputContainerLayoutManager) || (obj instanceof CyclingOutputContainerLayoutManager) || (obj instanceof DashboardLayoutManager) || (obj instanceof OutputContainerCell) || (obj instanceof OutputContainer) || (obj instanceof BeakerProgressUpdate) || (obj instanceof EasyForm) || (obj instanceof Color)) { logger.debug("basic object"); jgen.writeObject(obj); } else return runThreadSerializers(obj, jgen, expand) || runConfiguredSerializers(obj, jgen, expand); return true; } BasicObjectSerializer(); @Override String convertType(String tn); @Override boolean isPrimitiveType(String tn); @Override boolean writeObject(Object obj, JsonGenerator jgen, boolean expand); boolean runThreadSerializers(Object obj, JsonGenerator jgen, boolean expand); boolean runConfiguredSerializers(Object obj, JsonGenerator jgen, boolean expand); @Override Object deserialize(JsonNode n, ObjectMapper mapper); @Override void addTypeConversion(String from, String to); @Override void addTypeDeserializer(ObjectDeserializer o); @Override void addTypeSerializer(ObjectSerializer o); @Override void addfTypeDeserializer(ObjectDeserializer o); @Override void addfTypeSerializer(ObjectSerializer o); @Override void addThreadSpecificTypeConversion(String from, String to); @Override void addThreadSpecificTypeDeserializer(ObjectDeserializer o); @Override void addThreadSpecificTypeSerializer(ObjectSerializer o); @Override void addKnownBeakerType(String t); @Override boolean isKnownBeakerType(String t); static final String TYPE_INTEGER; static final String TYPE_LONG; static final String TYPE_BIGINT; static final String TYPE_DOUBLE; static final String TYPE_STRING; static final String TYPE_BOOLEAN; static final String TYPE_TIME; static final String TYPE_SELECT; }
@Test public void serializeMap_returnTrue() throws Exception { Map<String, String> map = new HashMap<String, String>(){ { put("key", "value"); } }; boolean result = basicObjectSerializer.writeObject(map, jgen, true); Assertions.assertThat(result).isTrue(); } @Test public void serializeArray_returnTrue() throws Exception { boolean result = basicObjectSerializer.writeObject( Arrays.asList("v1", "v2"), jgen, true); Assertions.assertThat(result).isTrue(); } @Test public void serializeListOfList_returnTrue() throws Exception { boolean result = basicObjectSerializer.writeObject( Arrays.asList(Arrays.asList("k1", 1), Arrays.asList("k2", 2)), jgen, true); Assertions.assertThat(result).isTrue(); }
CollectionDeserializer implements ObjectDeserializer { @Override public Object deserialize(JsonNode n, ObjectMapper mapper) { List<Object> o = new ArrayList<Object>(); try { logger.debug("using custom array deserializer"); for(int i=0; i<n.size(); i++) { o.add(parent.deserialize(n.get(i), mapper)); } } catch (Exception e) { logger.error("exception deserializing Collection ", e); o = null; } return o; } CollectionDeserializer(BeakerObjectConverter p); @Override boolean canBeUsed(JsonNode n); @Override Object deserialize(JsonNode n, ObjectMapper mapper); }
@Test public void deserialize_resultObjectHasValues() throws Exception { ObjectMapper mapper = new ObjectMapper(); JsonNode actualObj = mapper.readTree("[\"1\",\"2\",\"3\"]"); CollectionDeserializer deserializer = new CollectionDeserializer(new BasicObjectSerializer()); List list = (List) deserializer.deserialize(actualObj, mapper); Assertions.assertThat(list).isNotNull(); Assertions.assertThat(list.size()).isEqualTo(3); }
ColorDeserializer implements ObjectDeserializer { @Override public Object deserialize(JsonNode n, ObjectMapper mapper) { Object o = null; try { long i = Long.parseLong(n.asText().substring(1), 16); o = new Color((int)((i >> 16) & 0xFF), (int)((i >> 8) & 0xFF), (int)( i & 0xFF), (int)((i >> 24) & 0xFF)); } catch (Exception e) { logger.error("exception deserializing Color {}", e.getMessage()); } return o; } ColorDeserializer(BeakerObjectConverter p); @Override boolean canBeUsed(JsonNode n); @Override Object deserialize(JsonNode n, ObjectMapper mapper); }
@Test public void deserialize_resultObjectHasColor() throws Exception { ObjectMapper mapper = new ObjectMapper(); JsonNode actualObj = mapper.readTree("\"#FF00FF00\""); ColorDeserializer deserializer = new ColorDeserializer(new BasicObjectSerializer()); Color color = (Color) deserializer.deserialize(actualObj, mapper); Assertions.assertThat(color).isNotNull(); Assertions.assertThat(color.getRGB()).isEqualTo(Color.GREEN.getRGB()); }
UpdatableEvaluationResult extends Observable { public void setValue(Object o) { value = o; setChanged(); notifyObservers(); } UpdatableEvaluationResult(Object value); Object getValue(); void setValue(Object o); }
@Test public void setValue_shouldNotifyObserver() throws Exception { UpdatableEvaluationResult result = new UpdatableEvaluationResult("test"); ObserverObjectTest observer = new ObserverObjectTest(); result.addObserver(observer); result.setValue("test"); Assertions.assertThat(observer.getObjectList().get(0)).isEqualTo(result); }
SimpleEvaluationObject extends Observable { public synchronized void started() { setOutputHandler(); this.status = EvaluationStatus.RUNNING; setChanged(); notifyObservers(); } SimpleEvaluationObject(String e, final KernelFunctionality.ExecuteCodeCallback executeCodeCallback); void executeCodeCallback(); synchronized void started(); synchronized void finished(Object r); synchronized void error(Object r); synchronized void update(Object r); String getExpression(); synchronized EvaluationStatus getStatus(); synchronized Object getPayload(); void structuredUpdate(String message, int progress); synchronized BeakerOutputHandler getStdOutputHandler(); synchronized BeakerOutputHandler getStdErrorHandler(); void setOutputHandler(); void clrOutputHandler(); Message getJupyterMessage(); void setJupyterMessage(Message jupyterMessage); int getExecutionCount(); void setExecutionCount(int executionCount); Queue<ConsoleOutput> getConsoleOutput(); @Override String toString(); List<Object> getOutputdata(); void appendOutput(String s); void appendError(String s); }
@Test public void seoStarted_shouldNotifyObserver() throws Exception { seo.started(); Assertions.assertThat(observer.getObjectList().get(0)).isEqualTo(seo); }
SimpleEvaluationObject extends Observable { public synchronized void finished(Object r) { clrOutputHandler(); this.status = EvaluationStatus.FINISHED; payload = r; setChanged(); notifyObservers(); } SimpleEvaluationObject(String e, final KernelFunctionality.ExecuteCodeCallback executeCodeCallback); void executeCodeCallback(); synchronized void started(); synchronized void finished(Object r); synchronized void error(Object r); synchronized void update(Object r); String getExpression(); synchronized EvaluationStatus getStatus(); synchronized Object getPayload(); void structuredUpdate(String message, int progress); synchronized BeakerOutputHandler getStdOutputHandler(); synchronized BeakerOutputHandler getStdErrorHandler(); void setOutputHandler(); void clrOutputHandler(); Message getJupyterMessage(); void setJupyterMessage(Message jupyterMessage); int getExecutionCount(); void setExecutionCount(int executionCount); Queue<ConsoleOutput> getConsoleOutput(); @Override String toString(); List<Object> getOutputdata(); void appendOutput(String s); void appendError(String s); }
@Test public void seoFinished_shouldNotifyObserver() throws Exception { seo.finished(new Object()); Assertions.assertThat(observer.getObjectList().get(0)).isEqualTo(seo); }
GroovyKernelInfoHandler extends KernelHandler<Message> { @Override public void handle(Message message) { wrapBusyIdle(kernel, message, () -> { handleMsg(message); }); } GroovyKernelInfoHandler(KernelFunctionality kernel); @Override void handle(Message message); }
@Test public void handle_shouldSendMessage() throws Exception { handler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); } @Test public void handle_sentMessageHasContent() throws Exception { handler.handle(message); Message sentMessage = kernel.getSentMessages().get(0); Assertions.assertThat(sentMessage.getContent()).isNotEmpty(); } @Test public void handle_sentMessageHasHeaderTypeIsKernelInfoReply() throws Exception { handler.handle(message); Message sentMessage = kernel.getSentMessages().get(0); Header header = sentMessage.getHeader(); Assertions.assertThat(header).isNotNull(); Assertions.assertThat(header.getType()).isEqualTo(KERNEL_INFO_REPLY.getName()); } @Test public void handle_sentMessageHasLanguageInfo() throws Exception { handler.handle(message); Message sentMessage = kernel.getSentMessages().get(0); Map<String, Serializable> map = sentMessage.getContent(); Assertions.assertThat(map).isNotNull(); Assertions.assertThat(map.get("language_info")).isNotNull(); } @Test public void handle_messageContentHasGroovyLabel() throws Exception { handler.handle(message); Message sentMessage = kernel.getSentMessages().get(0); Map<String, Serializable> map = sentMessage.getContent(); Assertions.assertThat(map).isNotNull(); Assertions.assertThat(map.get("implementation")).isEqualTo("groovy"); }
SimpleEvaluationObject extends Observable { public synchronized void error(Object r) { clrOutputHandler(); this.status = EvaluationStatus.ERROR; payload = r; setChanged(); notifyObservers(); } SimpleEvaluationObject(String e, final KernelFunctionality.ExecuteCodeCallback executeCodeCallback); void executeCodeCallback(); synchronized void started(); synchronized void finished(Object r); synchronized void error(Object r); synchronized void update(Object r); String getExpression(); synchronized EvaluationStatus getStatus(); synchronized Object getPayload(); void structuredUpdate(String message, int progress); synchronized BeakerOutputHandler getStdOutputHandler(); synchronized BeakerOutputHandler getStdErrorHandler(); void setOutputHandler(); void clrOutputHandler(); Message getJupyterMessage(); void setJupyterMessage(Message jupyterMessage); int getExecutionCount(); void setExecutionCount(int executionCount); Queue<ConsoleOutput> getConsoleOutput(); @Override String toString(); List<Object> getOutputdata(); void appendOutput(String s); void appendError(String s); }
@Test public void seoError_shouldNotifyObserver() throws Exception { seo.error(new Object()); Assertions.assertThat(observer.getObjectList().get(0)).isEqualTo(seo); }
SimpleEvaluationObject extends Observable { public synchronized void update(Object r) { this.status = EvaluationStatus.RUNNING; payload = r; setChanged(); notifyObservers(); } SimpleEvaluationObject(String e, final KernelFunctionality.ExecuteCodeCallback executeCodeCallback); void executeCodeCallback(); synchronized void started(); synchronized void finished(Object r); synchronized void error(Object r); synchronized void update(Object r); String getExpression(); synchronized EvaluationStatus getStatus(); synchronized Object getPayload(); void structuredUpdate(String message, int progress); synchronized BeakerOutputHandler getStdOutputHandler(); synchronized BeakerOutputHandler getStdErrorHandler(); void setOutputHandler(); void clrOutputHandler(); Message getJupyterMessage(); void setJupyterMessage(Message jupyterMessage); int getExecutionCount(); void setExecutionCount(int executionCount); Queue<ConsoleOutput> getConsoleOutput(); @Override String toString(); List<Object> getOutputdata(); void appendOutput(String s); void appendError(String s); }
@Test public void seoUpdate_shouldNotifyObserver() throws Exception { seo.update(new Object()); Assertions.assertThat(observer.getObjectList().get(0)).isEqualTo(seo); }
SimpleEvaluationObject extends Observable { public synchronized BeakerOutputHandler getStdOutputHandler() { if (stdout == null) stdout = new SimpleOutputHandler(false); return stdout; } SimpleEvaluationObject(String e, final KernelFunctionality.ExecuteCodeCallback executeCodeCallback); void executeCodeCallback(); synchronized void started(); synchronized void finished(Object r); synchronized void error(Object r); synchronized void update(Object r); String getExpression(); synchronized EvaluationStatus getStatus(); synchronized Object getPayload(); void structuredUpdate(String message, int progress); synchronized BeakerOutputHandler getStdOutputHandler(); synchronized BeakerOutputHandler getStdErrorHandler(); void setOutputHandler(); void clrOutputHandler(); Message getJupyterMessage(); void setJupyterMessage(Message jupyterMessage); int getExecutionCount(); void setExecutionCount(int executionCount); Queue<ConsoleOutput> getConsoleOutput(); @Override String toString(); List<Object> getOutputdata(); void appendOutput(String s); void appendError(String s); }
@Test public void beakerOutputHandlerWriteBytesWithLength_shouldNotifyObserver() throws Exception { BeakerOutputHandler handler = seo.getStdOutputHandler(); handler.write("test".getBytes(), 0, 2); Assertions.assertThat(observer.getObjectList().get(0)).isEqualTo(seo); } @Test public void beakerOutputHandlerWriteInt_shouldNotifyObserver() throws Exception { BeakerOutputHandler handler = seo.getStdOutputHandler(); handler.write('t'); Assertions.assertThat(observer.getObjectList().get(0)).isEqualTo(seo); } @Test public void beakerOutputHandlerWriteBytes_shouldNotifyObserver() throws Exception { BeakerOutputHandler handler = seo.getStdOutputHandler(); handler.write("test".getBytes()); Assertions.assertThat(observer.getObjectList().get(0)).isEqualTo(seo); }
AbstractGridLayoutManager extends OutputContainerLayoutManager { public int getColumns() { return columns; } AbstractGridLayoutManager(int columns); int getColumns(); int getPaddingTop(); void setPaddingTop(int paddingTop); int getPaddingBottom(); void setPaddingBottom(int paddingBottom); int getPaddingLeft(); void setPaddingLeft(int paddingLeft); int getPaddingRight(); void setPaddingRight(int paddingRight); }
@Test public void createManagerWithParam_columnsEqualsParam() throws Exception { int columns = 5; AbstractGridLayoutManager manager = new AbstractGridLayoutManager(columns); Assertions.assertThat(manager.getColumns()).isEqualTo(columns); }
BeakerDashboard extends Observable { public dashRow newRow() { return new dashRow(); } BeakerDashboard(); String getTheStyle(); String getTheClass(); void setTheStyle(String s); void setTheClass(String s); List<dashRow> getRows(); void addRow(dashRow o); dashRow newRow(); dashColumn newColumn(int w); void clear(); void redraw(); final List<dashRow> content; }
@Test public void newRow_createNewDashRow() throws Exception { BeakerDashboard.dashRow row = dashboard.newRow(); Assertions.assertThat(row).isNotNull(); }
BeakerDashboard extends Observable { public dashColumn newColumn(int w) { return new dashColumn(w); } BeakerDashboard(); String getTheStyle(); String getTheClass(); void setTheStyle(String s); void setTheClass(String s); List<dashRow> getRows(); void addRow(dashRow o); dashRow newRow(); dashColumn newColumn(int w); void clear(); void redraw(); final List<dashRow> content; }
@Test public void newColumn_createNewColumnWithWidth() throws Exception { int width = 5; BeakerDashboard.dashColumn dashColumn = dashboard.newColumn(width); Assertions.assertThat(dashColumn).isNotNull(); Assertions.assertThat(dashColumn.getWidth()).isEqualTo(width); }
BeakerDashboard extends Observable { public void redraw() { setChanged(); notifyObservers(); } BeakerDashboard(); String getTheStyle(); String getTheClass(); void setTheStyle(String s); void setTheClass(String s); List<dashRow> getRows(); void addRow(dashRow o); dashRow newRow(); dashColumn newColumn(int w); void clear(); void redraw(); final List<dashRow> content; }
@Test public void redraw_shouldUpdateObservers() throws Exception { ObserverObjectTest observer = new ObserverObjectTest(); dashboard.addObserver(observer); dashboard.redraw(); Assertions.assertThat(observer.getObjectList()).isNotEmpty(); Assertions.assertThat(observer.getObjectList().get(0)).isEqualTo(dashboard); }
OutputContainer { public List<Object> getItems() { return items; } OutputContainer(); OutputContainer(List<Object> items); OutputContainer(List<Object> items, List<String> labels); void addItem(java.lang.Object item); void addItem(java.lang.Object item, int index); void addItem(java.lang.Object item, int index, java.lang.String label); void addItem(Object item, String label); void removeItem(int index); OutputContainer leftShift(Object item); void removeItem(Object itemToRemove); List<Object> getItems(); List<String> getLabels(); void visit(CellVisitor visitor); OutputContainerLayoutManager getLayoutManager(); void setLayoutManager(OutputContainerLayoutManager layoutManager); final static Logger LOGGER; }
@Test public void createWithItemsParam_hasThoseItems() throws Exception { List<Object> items = Arrays.asList(Boolean.FALSE, Integer.MAX_VALUE); OutputContainer container = new OutputContainer(items); Assertions.assertThat(container.getItems()).isEqualTo(items); }
ProgressReporting { public void structuredUpdate(String message, int progress) { if (progressBar == null) { progressBar = new IntProgress(); progressBar.display(); } progressBar.setValue(progress); progressBar.setDescription(message); } void structuredUpdate(String message, int progress); void close(); }
@Test public void structuredUpdate_shouldPublishMessages() throws Exception { progress.structuredUpdate("msg", 5); Assertions.assertThat(groovyKernel.getPublishedMessages()).isNotEmpty(); }
EvaluationResult { public Object getValue() { return value; } EvaluationResult(Object v); Object getValue(); }
@Test public void createManagerWithParam_valueEqualsThatParam() throws Exception { EvaluationResult result = new EvaluationResult(new Integer(123)); Assertions.assertThat(result.getValue()).isEqualTo(123); }
DynamicClassLoaderSimple extends ClassLoader { public Class<?> loadClass(String name) throws ClassNotFoundException { try { return getParent().loadClass(name); } catch (ClassNotFoundException cnfe) { } if(!name.startsWith("java")) { String cname = formatClassName(name); String fname = outDir + cname; File f = new File(fname); if (f.exists() && f.isFile()) { FileInputStream fis; try { fis = new FileInputStream(f); byte[] bytes = ByteStreams.toByteArray(fis); Class<?> result = getClass(name, bytes, true); if (result != null) { return result; } } catch (Exception e) { e.printStackTrace(); } } if (myloader != null) { Class<?> result = classes.get( name ); if (result != null) { return result; } InputStream is = myloader.getResourceAsStream(cname); if (is != null) { try { byte[] bytes = ByteStreams.toByteArray(is); result = getClass(name, bytes, true); if (result != null) { classes.put( name, result ); return result; } } catch (Exception e) { e.printStackTrace(); } } } } throw new ClassNotFoundException(); } DynamicClassLoaderSimple(ClassLoader classLoader); void addJars(List<String> dirs); void addDynamicDir(String o); Class<?> loadClass(String name); URL getResource(String name); InputStream getResourceAsStream(String name); Enumeration<URL> getResources(String name); }
@Test public void loadClassWithNameParam_returnClass() throws Exception { Class clazz = loader.loadClass(className); Assertions.assertThat(clazz).isNotNull(); }
DynamicClassLoaderSimple extends ClassLoader { public URL getResource(String name) { URL c; c = getParent().getResource(name); if (c == null && myloader != null) { c = myloader.getResource(name); } return c; } DynamicClassLoaderSimple(ClassLoader classLoader); void addJars(List<String> dirs); void addDynamicDir(String o); Class<?> loadClass(String name); URL getResource(String name); InputStream getResourceAsStream(String name); Enumeration<URL> getResources(String name); }
@Test public void getResourceWithNameParam_returnURL() throws Exception { URL url = loader.getResource(fileName); Assertions.assertThat(url).isNotNull(); }
DynamicClassLoaderSimple extends ClassLoader { public InputStream getResourceAsStream(String name) { InputStream c; c = getParent().getResourceAsStream(name); if (c == null && myloader != null) { c = myloader.getResourceAsStream(name); } return c; } DynamicClassLoaderSimple(ClassLoader classLoader); void addJars(List<String> dirs); void addDynamicDir(String o); Class<?> loadClass(String name); URL getResource(String name); InputStream getResourceAsStream(String name); Enumeration<URL> getResources(String name); }
@Test public void getResourceAsStreamWithNameParam_returnInputStream() throws Exception { InputStream is = loader.getResourceAsStream(fileName); Assertions.assertThat(is).isNotNull(); }
DynamicClassLoaderSimple extends ClassLoader { public Enumeration<URL> getResources(String name) throws IOException { Enumeration<URL> c; c = getParent().getResources(name); if ((c == null || !c.hasMoreElements()) && myloader != null) { try { c = myloader.getResources(name); } catch(IOException e) { } } return c; } DynamicClassLoaderSimple(ClassLoader classLoader); void addJars(List<String> dirs); void addDynamicDir(String o); Class<?> loadClass(String name); URL getResource(String name); InputStream getResourceAsStream(String name); Enumeration<URL> getResources(String name); }
@Test public void getResourcesWithNameParam_returnURLs() throws Exception { Enumeration<URL> urls = loader.getResources(fileName); Assertions.assertThat(urls).isNotNull(); }
ClassUtils { protected Class<?> getClass(String name) throws ClassNotFoundException { try { if(loader!=null) return loader.loadClass(name); return Class.forName(name); } catch(Exception e) { return null; } } ClassUtils(ClassLoader l); ClassUtils(); void clear(); void defineVariable(String name, String type); String getVariableType(String name); void defineClassShortName(String name, String fqname); AutocompleteCandidate expandExpression(String txt, AutocompleteRegistry registry, int type); final int DO_STATIC; final int DO_NON_STATIC; final int DO_ALL; }
@Test public void getClass_returnClass() throws ClassNotFoundException { ClassUtils classUtils = new ClassUtils(); Assertions.assertThat(classUtils.getClass("java.lang.Boolean")).isNotNull(); } @Test public void getClassByLoader_returnClass() throws ClassNotFoundException { ClassLoader classLoader = getClass().getClassLoader(); ClassUtils classUtils = new ClassUtils(classLoader); Assertions.assertThat(classUtils.getClass("java.lang.Boolean")).isNotNull(); }
AutocompleteCandidate { public List<AutocompleteCandidate> getChildrens() { return children; } AutocompleteCandidate(int t, String k); AutocompleteCandidate(int t, String [] k); AutocompleteCandidate(int t, String[] k, int max); AutocompleteCandidate clone(); void addChildren(AutocompleteCandidate a); int getType(); String getKey(); boolean hasChildren(); List<AutocompleteCandidate> getChildrens(); void addChildrens(List<AutocompleteCandidate> chs); void searchCandidates(List<String> ret, AutocompleteCandidate a); AutocompleteCandidate findLeaf(); }
@Test public void createWithTypeAndKey_hasChildrenIsNull(){ AutocompleteCandidate aCandidate = new AutocompleteCandidate(1, "key"); Assertions.assertThat(aCandidate.getChildrens()).isNull(); } @Test public void createWithMaxNumKeysIsTwo_hasOneElementOfChildrens(){ AutocompleteCandidate aCandidate = new AutocompleteCandidate(1, keys, 2); Assertions.assertThat(aCandidate.getChildrens()).isNotEmpty(); AutocompleteCandidate child = aCandidate.getChildrens().get(0); Assertions.assertThat(child.getChildrens()).isNull(); }
EvaluatorManager { public synchronized void setShellOptions(final KernelParameters kernelParameters) { try { evaluator.setShellOptions(kernelParameters); } catch (IOException e) { logger.error("Error while setting Shell Options", e); } evaluator.startWorker(); } EvaluatorManager(KernelFunctionality kernel, Evaluator evaluator); synchronized void setShellOptions(final KernelParameters kernelParameters); AutocompleteResult autocomplete(String code, int caretPosition); synchronized void killAllThreads(); synchronized SimpleEvaluationObject executeCode(String code, Message message, int executionCount, KernelFunctionality.ExecuteCodeCallback executeCodeCallback); void exit(); static Logger logger; }
@Test public void setShellOptions_callEvaluatorToStartWorker() throws Exception { evaluator.clearStartWorkerFlag(); evaluatorManager.setShellOptions(new KernelParameters(new HashedMap())); Assertions.assertThat(evaluator.isCallStartWorker()).isTrue(); }
EvaluatorManager { public synchronized void killAllThreads() { evaluator.killAllThreads(); } EvaluatorManager(KernelFunctionality kernel, Evaluator evaluator); synchronized void setShellOptions(final KernelParameters kernelParameters); AutocompleteResult autocomplete(String code, int caretPosition); synchronized void killAllThreads(); synchronized SimpleEvaluationObject executeCode(String code, Message message, int executionCount, KernelFunctionality.ExecuteCodeCallback executeCodeCallback); void exit(); static Logger logger; }
@Test public void killAllThreads_callEvaluatorToKillAllThreads() throws Exception { evaluatorManager.killAllThreads(); Assertions.assertThat(evaluator.isCallKillAllThreads()).isTrue(); }
EvaluatorManager { public void exit() { evaluator.exit(); } EvaluatorManager(KernelFunctionality kernel, Evaluator evaluator); synchronized void setShellOptions(final KernelParameters kernelParameters); AutocompleteResult autocomplete(String code, int caretPosition); synchronized void killAllThreads(); synchronized SimpleEvaluationObject executeCode(String code, Message message, int executionCount, KernelFunctionality.ExecuteCodeCallback executeCodeCallback); void exit(); static Logger logger; }
@Test public void exit_callEvaluatorToExit() throws Exception { evaluatorManager.exit(); Assertions.assertThat(evaluator.isCallExit()).isTrue(); }
EvaluatorManager { public synchronized SimpleEvaluationObject executeCode(String code, Message message, int executionCount, KernelFunctionality.ExecuteCodeCallback executeCodeCallback) { SimpleEvaluationObject seo = new SimpleEvaluationObject(code, executeCodeCallback); seo.setJupyterMessage(message); seo.setExecutionCount(executionCount); seo.addObserver(kernel.getExecutionResultSender()); evaluator.evaluate(seo, code); return seo; } EvaluatorManager(KernelFunctionality kernel, Evaluator evaluator); synchronized void setShellOptions(final KernelParameters kernelParameters); AutocompleteResult autocomplete(String code, int caretPosition); synchronized void killAllThreads(); synchronized SimpleEvaluationObject executeCode(String code, Message message, int executionCount, KernelFunctionality.ExecuteCodeCallback executeCodeCallback); void exit(); static Logger logger; }
@Test public void executeCode_callEvaluatorToEvaluate(){ String code = "test code"; evaluatorManager.executeCode(code, new Message(), 5, new ExecuteCodeCallbackTest()); Assertions.assertThat(evaluator.getCode()).isEqualTo(code); }
LegendPosition implements java.io.Serializable { public Position getPosition() { return position; } LegendPosition(); LegendPosition(Position position); LegendPosition(int[] coordinates); Position getPosition(); void setPosition(Position position); int getX(); void setX(int x); int getY(); void setY(int y); final static LegendPosition TOP; final static LegendPosition LEFT; final static LegendPosition BOTTOM; final static LegendPosition RIGHT; final static LegendPosition TOP_LEFT; final static LegendPosition TOP_RIGHT; final static LegendPosition BOTTOM_LEFT; final static LegendPosition BOTTOM_RIGHT; }
@Test public void createLegendPositionByEmptyConstructor_hasPositionIsNotNull() { LegendPosition legendPosition = new LegendPosition(); Assertions.assertThat(legendPosition.getPosition()).isNotNull(); } @Test public void createLegendPositionWithLeftPositionParam_hasLeftPosition() { LegendPosition legendPosition = new LegendPosition(LegendPosition.Position.LEFT); Assertions.assertThat(legendPosition.getPosition()).isEqualTo(LegendPosition.Position.LEFT); }
ChartUtils { public static List<Object> convertColors(List colors, String errorMsg) { List<Object> clist = new ArrayList<>(colors.size()); for(Object c : colors){ if (c instanceof Color) { clist.add(c); } else if (c instanceof java.awt.Color) { clist.add(new Color((java.awt.Color) c)); } else if (c instanceof List) { clist.add(convertColors((List)c, errorMsg)); } else { throw new IllegalArgumentException(errorMsg); } } return clist; } static List<Object> convertColors(List colors, String errorMsg); }
@Test public void callConvertColorsWithAwtColorListParam_shouldReturnBeakerChartColorList() { List<Object> outlineColors = ChartUtils.convertColors( Arrays.asList(java.awt.Color.BLACK, java.awt.Color.GREEN), "takes Color or List of Color"); Assertions.assertThat(outlineColors.get(0) instanceof Color).isTrue(); Assertions.assertThat(outlineColors.get(1) instanceof Color).isTrue(); } @Test(expected = IllegalArgumentException.class) public void callConvertColorsWithNumberListParam_throwIllegalArgumentException() { ChartUtils.convertColors(Arrays.asList(100, 200), "takes Color or List of Color"); }
AreaSerializer extends BasedXYGraphicsSerializer<Area> { @Override public void serialize(Area area, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException { jgen.writeStartObject(); super.serialize(area, jgen, sp); if (area.getColor() instanceof Color) { jgen.writeObjectField("color", area.getColor()); } if (area.getInterpolation() != null) { jgen.writeObjectField("interpolation", area.getInterpolation()); } jgen.writeEndObject(); } @Override void serialize(Area area, JsonGenerator jgen, SerializerProvider sp); }
@Test public void serializeInterpolationArea_resultJsonHasInterpolation() throws IOException { Area area = new Area(); area.setInterpolation(1); areaSerializer.serialize(area, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("interpolation")).isTrue(); Assertions.assertThat(actualObj.get("interpolation").asInt()).isEqualTo(1); } @Test public void serializeColorArea_resultJsonHasColor() throws IOException { Area area = new Area(); area.setColor(Color.GREEN); areaSerializer.serialize(area, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("color")).isTrue(); Assertions.assertThat(actualObj.get("color").get("rgb").asInt()) .isEqualTo(Color.GREEN.getRGB()); }
StemsSerializer extends BasedXYGraphicsSerializer<Stems> { @Override public void serialize(Stems stems, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException { jgen.writeStartObject(); super.serialize(stems, jgen, sp); if (stems.getColors() != null) { jgen.writeObjectField("colors", stems.getColors()); } else { jgen.writeObjectField("color", stems.getColor()); } if (stems.getWidth() != null) { jgen.writeObjectField("width", stems.getWidth()); } if (stems.getStyles() != null) { jgen.writeObjectField("styles", stems.getStyles()); } else { jgen.writeObjectField("style", stems.getStyle().toString()); } jgen.writeEndObject(); } @Override void serialize(Stems stems, JsonGenerator jgen, SerializerProvider sp); }
@Test public void serializeColorsStems_resultJsonHasColors() throws IOException { Stems stems = new Stems(); stems.setColor(Arrays.asList(Color.BLUE, Color.GREEN, Color.BLACK)); stemsSerializer.serialize(stems, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("colors")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("colors"); Assertions.assertThat(arrayNode.get(1).get("rgb").asInt()).isEqualTo(Color.GREEN.getRGB()); } @Test public void serializeColorStems_resultJsonHasColor() throws IOException { Stems stems = new Stems(); stems.setColor(Color.GREEN); stemsSerializer.serialize(stems, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("color")).isTrue(); Assertions.assertThat(actualObj.get("color").get("rgb").asInt()) .isEqualTo(Color.GREEN.getRGB()); } @Test public void serializeWidthStems_resultJsonHasWidth() throws IOException { Stems stems = new Stems(); stems.setWidth(11f); stemsSerializer.serialize(stems, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("width")).isTrue(); Assertions.assertThat(actualObj.get("width").asInt()).isEqualTo(11); } @Test public void serializeStrokeTypeStems_resultJsonHasStyle() throws IOException { Stems stems = new Stems(); stems.setStyle(StrokeType.SOLID); stemsSerializer.serialize(stems, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("style")).isTrue(); Assertions.assertThat(actualObj.get("style").asText()).isEqualTo("SOLID"); } @Test public void serializeStrokeTypeListStems_resultJsonHasStyles() throws IOException { Stems stems = new Stems(); stems.setStyle(Arrays.asList(StrokeType.SOLID, StrokeType.DASHDOT)); stemsSerializer.serialize(stems, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("styles")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("styles"); Assertions.assertThat(arrayNode.get(1).asText()).isEqualTo("DASHDOT"); }
CategoryStemsSerializer extends CategoryGraphicsSerializer<CategoryStems> { @Override public void serialize(CategoryStems categoryStems, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartObject(); super.serialize(categoryStems, jgen, provider); if (categoryStems.getBases() != null) { jgen.writeObjectField("bases", categoryStems.getBases()); } else { jgen.writeObjectField("base", categoryStems.getBase()); } if (categoryStems.getWidth() != null) { jgen.writeObjectField("width", categoryStems.getWidth()); } if (categoryStems.getStyles() != null) { jgen.writeObjectField("styles", categoryStems.getStyles()); } else { jgen.writeObjectField("style", categoryStems.getStyle().toString()); } jgen.writeEndObject(); } @Override void serialize(CategoryStems categoryStems, JsonGenerator jgen, SerializerProvider provider); }
@Test public void serializeBasesCategoryStems_resultJsonHasBases() throws IOException { CategoryStems categoryStems = new CategoryStems(); categoryStems.setBase(Arrays.asList(11, 22, 33)); categoryStemsSerializer.serialize(categoryStems, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("bases")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("bases"); Assertions.assertThat(arrayNode.get(1).asInt()).isEqualTo(22); } @Test public void serializeBaseCategoryStems_resultJsonHasBase() throws IOException { CategoryStems categoryStems = new CategoryStems(); categoryStems.setBase(11); categoryStemsSerializer.serialize(categoryStems, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("base")).isTrue(); Assertions.assertThat(actualObj.get("base").asInt()).isEqualTo(11); } @Test public void serializeWidthCategoryStems_resultJsonHasWidth() throws IOException { CategoryStems categoryStems = new CategoryStems(); categoryStems.setWidth(11f); categoryStemsSerializer.serialize(categoryStems, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("width")).isTrue(); Assertions.assertThat(actualObj.get("width").asInt()).isEqualTo(11); } @Test public void serializeStrokeTypeCategoryStems_resultJsonHasStyle() throws IOException { CategoryStems categoryStems = new CategoryStems(); categoryStems.setStyle(StrokeType.SOLID); categoryStemsSerializer.serialize(categoryStems, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("style")).isTrue(); Assertions.assertThat(actualObj.get("style").asText()).isEqualTo("SOLID"); } @Test public void serializeStrokeTypeListCategoryStems_resultJsonHasStyles() throws IOException { CategoryStems categoryStems = new CategoryStems(); categoryStems.setStyle(Arrays.asList(StrokeType.SOLID, StrokeType.DASHDOT)); categoryStemsSerializer.serialize(categoryStems, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("styles")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("styles"); Assertions.assertThat(arrayNode.get(1).asText()).isEqualTo("DASHDOT"); }
LineSerializer extends XYGraphicsSerializer<Line> { @Override public void serialize(Line line, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException { jgen.writeStartObject(); super.serialize(line, jgen, sp); if (line.getLodFilter() != null) jgen.writeObjectField("lod_filter", line.getLodFilter().getText()); if (line.getColor() instanceof Color) { jgen.writeObjectField("color", line.getColor()); } if (line.getWidth() != null) { jgen.writeObjectField("width", line.getWidth()); } if (line.getStyle() != null) { jgen.writeObjectField("style", line.getStyle().toString()); } if (line.getInterpolation() != null) { jgen.writeObjectField("interpolation", line.getInterpolation()); } jgen.writeEndObject(); } @Override void serialize(Line line, JsonGenerator jgen, SerializerProvider sp); }
@Test public void serializeWidthLine_resultJsonHasWidth() throws IOException { Line line = new Line(); line.setWidth(1f); lineSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("width")).isTrue(); Assertions.assertThat(actualObj.get("width").asDouble()).isEqualTo(1.0); } @Test public void serializeColorLine_resultJsonHasColor() throws IOException { Line line = new Line(); line.setColor(Color.GREEN); lineSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("color")).isTrue(); Assertions.assertThat(actualObj.get("color").get("rgb").asInt()) .isEqualTo(Color.GREEN.getRGB()); } @Test public void serializeStrokeTypeLine_resultJsonHasStyle() throws IOException { Line line = new Line(); line.setStyle(StrokeType.SOLID); lineSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("style")).isTrue(); Assertions.assertThat(actualObj.get("style").asText()).isEqualTo("SOLID"); } @Test public void serializeInterpolationLine_resultJsonHasInterpolation() throws IOException { Line line = new Line(); line.setInterpolation(1); lineSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("interpolation")).isTrue(); Assertions.assertThat(actualObj.get("interpolation").asInt()).isEqualTo(1); } @Test public void serializeLodFilterLine_resultJsonHasLodFilter() throws IOException { Line line = new Line(); line.setLodFilter(Filter.LINE); lineSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("lod_filter")).isTrue(); Assertions.assertThat(actualObj.get("lod_filter").asText()).isEqualTo("line"); }
BasedXYGraphicsSerializer extends XYGraphicsSerializer<T> { @Override public void serialize(T basedXYGraphics, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException { super.serialize(basedXYGraphics, jgen, sp); if (basedXYGraphics.getBases() != null) { jgen.writeObjectField("bases", basedXYGraphics.getBases()); } else { jgen.writeObjectField("base", basedXYGraphics.getBase()); } } @Override void serialize(T basedXYGraphics, JsonGenerator jgen, SerializerProvider sp); }
@Test public void serializeBasesOfBasedXYGraphics_resultJsonHasBases() throws IOException { Area area = new Area(); area.setBase(Arrays.asList(11, 22, 33)); basedXYGraphicsSerializer.serialize(area, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("bases")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("bases"); Assertions.assertThat(arrayNode.get(1).asInt()).isEqualTo(22); } @Test public void serializeBaseOfBasedXYGraphics_resultJsonHasBase() throws IOException { Area area = new Area(); area.setBase(11); basedXYGraphicsSerializer.serialize(area, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("base")).isTrue(); Assertions.assertThat(actualObj.get("base").asInt()).isEqualTo(11); }
HistogramSerializer extends AbstractChartSerializer<Histogram> { @Override public void serialize(Histogram histogram, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartObject(); serialize(histogram, jgen); if (histogram.getColors() != null) { jgen.writeObjectField(COLORS, histogram.getColors()); } else { jgen.writeObjectField(COLOR, histogram.getColor()); } if (histogram.getListData() != null) { jgen.writeObjectField(GRAPHICS_LIST, histogram.getListData()); } else { jgen.writeObjectField(GRAPHICS_LIST, Arrays.asList(histogram.getData())); } jgen.writeObjectField("right_close", histogram.getRightClose()); if (histogram.getRangeMin() != null) jgen.writeObjectField("range_min", histogram.getRangeMin()); if (histogram.getRangeMax() != null) jgen.writeObjectField("range_max", histogram.getRangeMax()); jgen.writeObjectField(BIN_COUNT, histogram.getBinCount()); jgen.writeObjectField(CUMULATIVE, histogram.getCumulative()); jgen.writeObjectField(NORMED, histogram.getNormed()); jgen.writeObjectField(LOG, histogram.getLog()); jgen.writeObjectField(DISPLAY_MODE, histogram.getDisplayMode()); jgen.writeObjectField(NAMES, histogram.getNames()); jgen.writeEndObject(); } @Override void serialize(Histogram histogram, JsonGenerator jgen, SerializerProvider provider); static final String GRAPHICS_LIST; static final String BIN_COUNT; static final String COLOR; static final String COLORS; static final String NAMES; static final String DISPLAY_MODE; static final String CUMULATIVE; static final String NORMED; static final String LOG; }
@Test public void serializeColorOfHistogram_resultJsonHasColor() throws IOException { histogram.setColor(Color.GREEN); histogramSerializer.serialize(histogram, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("color")).isTrue(); Assertions.assertThat(actualObj.get("color").get("rgb").asInt()) .isEqualTo(Color.GREEN.getRGB()); } @Test public void serializeColorsOfHistogram_resultJsonHasColors() throws IOException { histogram.setColor(Arrays.asList(Color.GREEN, Color.BLUE)); histogramSerializer.serialize(histogram, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("colors")).isTrue(); Assertions.assertThat(actualObj.get("colors")).isNotEmpty(); } @Test public void serializeDataListOfHistogram_resultJsonHasGraphicsList() throws IOException { histogram.setData(Arrays.asList(1, 2)); histogramSerializer.serialize(histogram, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("graphics_list")).isTrue(); Assertions.assertThat(actualObj.get("graphics_list")).isNotEmpty(); } @Test public void serializeDataListListOfHistogram_resultJsonHasGraphicsList() throws IOException { histogram.setData(Arrays.asList(Arrays.asList(1, 2), Arrays.asList(3, 4))); histogramSerializer.serialize(histogram, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("graphics_list")).isTrue(); Assertions.assertThat(actualObj.get("graphics_list")).isNotEmpty(); } @Test public void serializeRightCloseOfHistogram_resultJsonHasRightClose() throws IOException { histogram.setRightClose(true); histogramSerializer.serialize(histogram, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("right_close")).isTrue(); Assertions.assertThat(actualObj.get("right_close").asBoolean()).isTrue(); } @Test public void serializeRangeMinOfHistogram_resultJsonHasRangeMin() throws IOException { histogram.setRangeMin(11); histogramSerializer.serialize(histogram, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("range_min")).isTrue(); Assertions.assertThat(actualObj.get("range_min").asInt()).isEqualTo(11); } @Test public void serializeRangeMaxOfHistogram_resultJsonHasRangeMax() throws IOException { histogram.setRangeMax(11); histogramSerializer.serialize(histogram, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("range_max")).isTrue(); Assertions.assertThat(actualObj.get("range_max").asInt()).isEqualTo(11); } @Test public void serializeBinCountOfHistogram_resultJsonHasBinCount() throws IOException { histogram.setBinCount(11); histogramSerializer.serialize(histogram, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("bin_count")).isTrue(); Assertions.assertThat(actualObj.get("bin_count").asInt()).isEqualTo(11); } @Test public void serializeCumulativeOfHistogram_resultJsonHasCumulative() throws IOException { histogram.setCumulative(true); histogramSerializer.serialize(histogram, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("cumulative")).isTrue(); Assertions.assertThat(actualObj.get("cumulative").asBoolean()).isTrue(); } @Test public void serializeNormedOfHistogram_resultJsonHasNormed() throws IOException { histogram.setNormed(true); histogramSerializer.serialize(histogram, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("normed")).isTrue(); Assertions.assertThat(actualObj.get("normed").asBoolean()).isTrue(); } @Test public void serializeLogOfHistogram_resultJsonHasLog() throws IOException { histogram.setLog(true); histogramSerializer.serialize(histogram, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("log")).isTrue(); Assertions.assertThat(actualObj.get("log").asBoolean()).isTrue(); } @Test public void serializeDisplayModeOfHistogram_resultJsonHasDisplayMode() throws IOException { histogram.setDisplayMode(Histogram.DisplayMode.STACK); histogramSerializer.serialize(histogram, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("displayMode")).isTrue(); Assertions.assertThat(actualObj.get("displayMode").asText()).isEqualTo("STACK"); } @Test public void serializeNamesOfHistogram_resultJsonHasNames() throws IOException { histogram.setNames(Arrays.asList("name1", "name2")); histogramSerializer.serialize(histogram, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("names")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("names"); Assertions.assertThat(arrayNode.get(1).asText()).isEqualTo("name2"); }
SQLEvaluator implements Evaluator { public void evaluate(SimpleEvaluationObject seo, String code) { jobQueue.add(new JobDescriptor(code, seo)); syncObject.release(); } SQLEvaluator(String id, String sId); void evaluate(SimpleEvaluationObject seo, String code); @Override void startWorker(); void exit(); void killAllThreads(); @Override AutocompleteResult autocomplete(String code, int caretPosition); @Override void setShellOptions(final KernelParameters kernelParameters); void setShellUserPassword(String namedConnection, String user, String password); List<ConnectionStringBean> getListOfConnectiononWhoNeedDialog(); }
@Test public void evaluateSql() throws Exception { SimpleEvaluationObject seo = new SimpleEvaluationObject(CREATE_AND_SELECT_ALL, new ExecuteCodeCallbackTest()); sqlEvaluator.evaluate(seo, CREATE_AND_SELECT_ALL); waitForResult(seo); verifyResult(seo); }
CppKernelInfoHandler extends KernelHandler<Message> { @Override public void handle(Message message) { logger.debug("Processing Cpp kernel info request"); Message reply = new Message(); HashMap<String, Serializable> map = new HashMap<>(6); map.put("protocol_version", "5.0"); map.put("implementation", "cpp"); map.put("implementation_version", "1.0.0"); HashMap<String, Serializable> map1 = new HashMap<String, Serializable>(7); map1.put("name", "cpp"); map1.put("version", ""); map1.put("mimetype", ""); map1.put("file_extension", ".cpp"); map1.put("codemirror_mode", "C++"); map1.put("nbconverter_exporter", ""); map.put("language_info", map1); map.put("banner", "BeakerX kernel for C++"); map.put("beakerx", true); map.put("help_links", new ArrayList<String>()); reply.setContent(map); reply.setHeader(new Header(KERNEL_INFO_REPLY, message.getHeader().getSession())); reply.setParentHeader(message.getHeader()); reply.setIdentities(message.getIdentities()); send(reply); } CppKernelInfoHandler(KernelFunctionality kernel); @Override void handle(Message message); }
@Test public void handle_shouldSendMessage() throws Exception { handler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); } @Test public void handle_sentMessageHasContent() throws Exception { handler.handle(message); Message sentMessage = kernel.getSentMessages().get(0); Assertions.assertThat(sentMessage.getContent()).isNotEmpty(); } @Test public void handle_sentMessageHasHeaderTypeIsKernelInfoReply() throws Exception { handler.handle(message); Message sentMessage = kernel.getSentMessages().get(0); Header header = sentMessage.getHeader(); Assertions.assertThat(header).isNotNull(); Assertions.assertThat(header.getType()).isEqualTo(KERNEL_INFO_REPLY.getName()); } @Test public void handle_sentMessageHasLanguageInfo() throws Exception { handler.handle(message); Message sentMessage = kernel.getSentMessages().get(0); Map<String, Serializable> map = sentMessage.getContent(); Assertions.assertThat(map).isNotNull(); Assertions.assertThat(map.get("language_info")).isNotNull(); } @Test public void handle_messageContentHasCppLabel() throws Exception { handler.handle(message); Message sentMessage = kernel.getSentMessages().get(0); Map<String, Serializable> map = sentMessage.getContent(); Assertions.assertThat(map).isNotNull(); Assertions.assertThat(map.get("implementation")).isEqualTo("cpp"); }
CategoryBarsSerializer extends CategoryGraphicsSerializer<CategoryBars> { @Override public void serialize(CategoryBars categoryBars, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartObject(); super.serialize(categoryBars, jgen, provider); if (categoryBars.getBases() != null) { jgen.writeObjectField("bases", categoryBars.getBases()); } else { jgen.writeObjectField("base", categoryBars.getBase()); } if (categoryBars.getWidths() != null) { jgen.writeObjectField("widths", categoryBars.getWidths()); } else { jgen.writeObjectField("width", categoryBars.getWidth()); } if (categoryBars.getOutlineColors() != null) { jgen.writeObjectField("outline_colors", categoryBars.getOutlineColors()); } else { jgen.writeObjectField("outline_color", categoryBars.getOutlineColor()); } if (categoryBars.getFills() != null) { jgen.writeObjectField("fills", categoryBars.getFills()); } else { jgen.writeObjectField("fill", categoryBars.getFill()); } if (categoryBars.getDrawOutlines() != null) { jgen.writeObjectField("outlines", categoryBars.getDrawOutlines()); } else { jgen.writeObjectField("outline", categoryBars.getDrawOutline()); } jgen.writeObjectField("labelPosition", categoryBars.getLabelPosition()); jgen.writeEndObject(); } @Override void serialize(CategoryBars categoryBars, JsonGenerator jgen, SerializerProvider provider); }
@Test public void serializeBasesCategoryBars_resultJsonHasBases() throws IOException { CategoryBars categoryBars = new CategoryBars(); categoryBars.setBase(Arrays.asList(11, 22, 33)); categoryBarsSerializer.serialize(categoryBars, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("bases")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("bases"); Assertions.assertThat(arrayNode.get(1).asInt()).isEqualTo(22); } @Test public void serializeBaseCategoryBars_resultJsonHasBase() throws IOException { CategoryBars categoryBars = new CategoryBars(); categoryBars.setBase(11); categoryBarsSerializer.serialize(categoryBars, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("base")).isTrue(); Assertions.assertThat(actualObj.get("base").asInt()).isEqualTo(11); } @Test public void serializeWidthCategoryBars_resultJsonHasWidth() throws IOException { CategoryBars categoryBars = new CategoryBars(); categoryBars.setWidth(11); categoryBarsSerializer.serialize(categoryBars, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("width")).isTrue(); Assertions.assertThat(actualObj.get("width").asInt()).isEqualTo(11); } @Test public void serializeWidthsCategoryBars_resultJsonHasWidths() throws IOException { CategoryBars categoryBars = new CategoryBars(); categoryBars.setWidth(Arrays.asList(11, 22, 33)); categoryBarsSerializer.serialize(categoryBars, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("widths")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("widths"); Assertions.assertThat(arrayNode.get(1).asInt()).isEqualTo(22); } @Test public void serializeOutlineColorCategoryBars_resultJsonHasOutlineColor() throws IOException { CategoryBars categoryBars = new CategoryBars(); categoryBars.setOutlineColor(Color.GREEN); categoryBarsSerializer.serialize(categoryBars, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("outline_color")).isTrue(); Assertions.assertThat(actualObj.get("outline_color").get("rgb").asInt()) .isEqualTo(Color.GREEN.getRGB()); } @Test public void serializeOutlineColorsCategoryBars_resultJsonHasOutlineColors() throws IOException { CategoryBars categoryBars = new CategoryBars(); categoryBars.setOutlineColor(Arrays.asList(Color.BLUE, Color.GREEN, Color.BLACK)); categoryBarsSerializer.serialize(categoryBars, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("outline_colors")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("outline_colors"); Assertions.assertThat(arrayNode.get(1).get("rgb").asInt()).isEqualTo(Color.GREEN.getRGB()); } @Test public void serializeFillCategoryBars_resultJsonHasFill() throws IOException { CategoryBars categoryBars = new CategoryBars(); categoryBars.setFill(true); categoryBarsSerializer.serialize(categoryBars, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("fill")).isTrue(); Assertions.assertThat(actualObj.get("fill").asBoolean()).isTrue(); } @Test public void serializeFillsCategoryBars_resultJsonHasFills() throws IOException { CategoryBars categoryBars = new CategoryBars(); categoryBars.setFill(Arrays.asList(false, true, false)); categoryBarsSerializer.serialize(categoryBars, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("fills")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("fills"); Assertions.assertThat(arrayNode.get(1).asBoolean()).isTrue(); } @Test public void serializeDrawOutlineCategoryBars_resultJsonHasOutline() throws IOException { CategoryBars categoryBars = new CategoryBars(); categoryBars.setDrawOutline(true); categoryBarsSerializer.serialize(categoryBars, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("outline")).isTrue(); Assertions.assertThat(actualObj.get("outline").asBoolean()).isTrue(); } @Test public void serializeDrawOutlinesCategoryBars_resultJsonHasDrawOutlines() throws IOException { CategoryBars categoryBars = new CategoryBars(); categoryBars.setDrawOutline(Arrays.asList(false, true, false)); categoryBarsSerializer.serialize(categoryBars, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("outlines")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("outlines"); Assertions.assertThat(arrayNode.get(1).asBoolean()).isTrue(); } @Test public void serializeLabelPositionCategoryBars_resultJsonHasLabelPosition() throws IOException { CategoryBars categoryBars = new CategoryBars(); categoryBars.setLabelPosition(LabelPositionType.CENTER); categoryBarsSerializer.serialize(categoryBars, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("labelPosition")).isTrue(); Assertions.assertThat(actualObj.get("labelPosition").asText()).isEqualTo("CENTER"); }
ColorSerializer extends JsonSerializer<Color> { @Override public void serialize(Color color, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException { synchronized(color) { jgen.writeString(String.format("#%x", color.getRGB()).toUpperCase()); } } @Override void serialize(Color color, JsonGenerator jgen, SerializerProvider sp); }
@Test public void serializeColor_resultJsonHasColor() throws IOException { colorSerializer.serialize(Color.GREEN, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.asText()).isEqualTo("#FF00FF00"); }
YAxisSerializer extends JsonSerializer<YAxis> { @Override public void serialize(YAxis yAxis, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException { jgen.writeStartObject(); jgen.writeObjectField("type", yAxis.getClass().getSimpleName()); jgen.writeObjectField("label", yAxis.getLabel()); jgen.writeObjectField("auto_range", yAxis.getAutoRange()); jgen.writeObjectField("auto_range_includes_zero", yAxis.getAutoRangeIncludesZero()); jgen.writeObjectField("lower_margin", yAxis.getLowerMargin()); jgen.writeObjectField("upper_margin", yAxis.getUpperMargin()); jgen.writeObjectField("lower_bound", yAxis.getLowerBound()); jgen.writeObjectField("upper_bound", yAxis.getUpperBound()); jgen.writeObjectField("use_log", yAxis.getLog()); jgen.writeObjectField("log_base", yAxis.getLogBase()); jgen.writeEndObject(); } @Override void serialize(YAxis yAxis, JsonGenerator jgen, SerializerProvider sp); }
@Test public void serializeYAxis_resultJsonHasType() throws IOException { yAxisSerializer.serialize(yAxis, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("type")).isTrue(); Assertions.assertThat(actualObj.get("type").asText()).isEqualTo("YAxis"); } @Test public void serializeLabelOfYAxis_resultJsonHasLabel() throws IOException { yAxis.setLabel("some label"); yAxisSerializer.serialize(yAxis, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("label")).isTrue(); Assertions.assertThat(actualObj.get("label").asText()).isEqualTo("some label"); } @Test public void serializeAutoRangeOfYAxis_resultJsonHasAutoRange() throws IOException { yAxis.setAutoRange(true); yAxisSerializer.serialize(yAxis, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("auto_range")).isTrue(); Assertions.assertThat(actualObj.get("auto_range").asBoolean()).isTrue(); } @Test public void serializeAutoRangeIncludesZeroOfYAxis_resultJsonHasAutoRangeIncludesZero() throws IOException { yAxis.setAutoRangeIncludesZero(true); yAxisSerializer.serialize(yAxis, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("auto_range_includes_zero")).isTrue(); Assertions.assertThat(actualObj.get("auto_range_includes_zero").asBoolean()).isTrue(); } @Test public void serializeLowerMarginOfYAxis_resultJsonHasLowerMargin() throws IOException { yAxis.setLowerMargin(1.5); yAxisSerializer.serialize(yAxis, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("lower_margin")).isTrue(); Assertions.assertThat(actualObj.get("lower_margin").asDouble()).isEqualTo(1.5); } @Test public void serializeUpperMarginOfYAxis_resultJsonHasUpperMargin() throws IOException { yAxis.setUpperMargin(2.5); yAxisSerializer.serialize(yAxis, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("upper_margin")).isTrue(); Assertions.assertThat(actualObj.get("upper_margin").asDouble()).isEqualTo(2.5); } @Test public void serializeLogOfYAxis_resultJsonHasLog() throws IOException { yAxis.setLog(true); yAxisSerializer.serialize(yAxis, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("use_log")).isTrue(); Assertions.assertThat(actualObj.get("use_log").asBoolean()).isTrue(); } @Test public void serializeLogBaseOfYAxis_resultJsonHasLogBase() throws IOException { yAxis.setLogBase(1.5); yAxisSerializer.serialize(yAxis, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("log_base")).isTrue(); Assertions.assertThat(actualObj.get("log_base").asDouble()).isEqualTo(1.5); }
CombinedPlotSerializer extends ObservableChartSerializer<CombinedPlot> { @Override public void serialize(CombinedPlot plot, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException { jgen.writeStartObject(); super.serialize(plot, jgen); jgen.writeObjectField("type", plot.getClass().getSimpleName()); jgen.writeObjectField("init_width", plot.getInitWidth()); jgen.writeObjectField("init_height", plot.getInitHeight()); jgen.writeObjectField("title", plot.getTitle()); jgen.writeObjectField(X_LABEL, plot.getXLabel()); List<XYChart> subplots = plot.getSubplots(); if (!subplots.isEmpty()) { String plot_type = subplots.get(0).getClass().getSimpleName(); if ("SimpleTimePlot".equals(plot_type)){ jgen.writeObjectField("plot_type", "TimePlot"); }else { jgen.writeObjectField("plot_type", plot_type); } } jgen.writeObjectField("plots", subplots); jgen.writeObjectField("weights", plot.getWeights()); jgen.writeObjectField("version", "groovy"); jgen.writeObjectField("x_tickLabels_visible", plot.isxTickLabelsVisible()); jgen.writeObjectField("y_tickLabels_visible", plot.isyTickLabelsVisible()); jgen.writeEndObject(); } @Override void serialize(CombinedPlot plot, JsonGenerator jgen, SerializerProvider sp); static final String X_LABEL; }
@Test public void serializeCombinedPlot_resultJsonHasType() throws IOException { CombinedPlot combinedPlot = new CombinedPlot(); combinedPlotSerializer.serialize(combinedPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("type")).isTrue(); Assertions.assertThat(actualObj.get("type").asText()).isEqualTo("CombinedPlot"); } @Test public void serializeInitWidthOfCombinedPlot_resultJsonHasInitWidth() throws IOException { CombinedPlot combinedPlot = new CombinedPlot(); combinedPlot.setInitWidth(600); combinedPlotSerializer.serialize(combinedPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("init_width")).isTrue(); Assertions.assertThat(actualObj.get("init_width").asInt()).isEqualTo(600); } @Test public void serializeInitHeightOfCombinedPlot_resultJsonHasInitHeight() throws IOException { CombinedPlot combinedPlot = new CombinedPlot(); combinedPlot.setInitHeight(300); combinedPlotSerializer.serialize(combinedPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("init_height")).isTrue(); Assertions.assertThat(actualObj.get("init_height").asInt()).isEqualTo(300); } @Test public void serializeTitleOfCombinedPlot_resultJsonHasTitle() throws IOException { CombinedPlot combinedPlot = new CombinedPlot(); combinedPlot.setTitle("Some title"); combinedPlotSerializer.serialize(combinedPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("title")).isTrue(); Assertions.assertThat(actualObj.get("title").asText()).isEqualTo("Some title"); } @Test public void serializeXLabelNameOfCombinedPlot_resultJsonHasXLabelName() throws IOException { CombinedPlot combinedPlot = new CombinedPlot(); combinedPlot.setXLabel("X label name"); combinedPlotSerializer.serialize(combinedPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("x_label")).isTrue(); Assertions.assertThat(actualObj.get("x_label").asText()).isEqualTo("X label name"); } @Test public void serializePlotTypeOfCombinedPlot_resultJsonHasPlotType() throws IOException { CombinedPlot combinedPlot = new CombinedPlot(); combinedPlot.add(new Plot()); combinedPlot.add(new Plot()); combinedPlotSerializer.serialize(combinedPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("plot_type")).isTrue(); Assertions.assertThat(actualObj.get("plot_type").asText()).isEqualTo("Plot"); } @Test public void serializeTimePlotTypeOfCombinedPlot_resultJsonHasTimePlotType() throws IOException { CombinedPlot combinedPlot = new CombinedPlot(); combinedPlot.add( new SimpleTimePlot(createDataForSimpleTimePlot(), Arrays.asList("m3", "time"))); combinedPlotSerializer.serialize(combinedPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("plot_type")).isTrue(); Assertions.assertThat(actualObj.get("plot_type").asText()).isEqualTo("TimePlot"); } @Test public void serializePlotsOfCombinedPlot_resultJsonHasPlots() throws IOException { CombinedPlot combinedPlot = new CombinedPlot(); combinedPlot.add(new Plot()); combinedPlot.add(new Plot()); combinedPlotSerializer.serialize(combinedPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("plots")).isTrue(); Assertions.assertThat(actualObj.get("plots")).isNotEmpty(); } @Test public void serializeWeightsOfCombinedPlot_resultJsonHasWeights() throws IOException { CombinedPlot combinedPlot = new CombinedPlot(); combinedPlot.add(new Plot(), 3); combinedPlot.add(new Plot(), 3); combinedPlotSerializer.serialize(combinedPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("weights")).isTrue(); Assertions.assertThat(actualObj.get("weights")).isNotEmpty(); } @Test public void serializeCombinedPlot_resultJsonHasVersion() throws IOException { CombinedPlot combinedPlot = new CombinedPlot(); combinedPlotSerializer.serialize(combinedPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("version")).isTrue(); Assertions.assertThat(actualObj.get("version").asText()).isEqualTo("groovy"); } @Test public void serializeXTickLabelsVisibleOfCombinedPlot_resultJsonHasXTickLabelsVisible() throws IOException { CombinedPlot combinedPlot = new CombinedPlot(); combinedPlot.setxTickLabelsVisible(true); combinedPlotSerializer.serialize(combinedPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("x_tickLabels_visible")).isTrue(); Assertions.assertThat(actualObj.get("x_tickLabels_visible").asBoolean()).isTrue(); } @Test public void serializeYTickLabelsVisibleOfCombinedPlot_resultJsonHasYTickLabelsVisible() throws IOException { CombinedPlot combinedPlot = new CombinedPlot(); combinedPlot.setyTickLabelsVisible(true); combinedPlotSerializer.serialize(combinedPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("y_tickLabels_visible")).isTrue(); Assertions.assertThat(actualObj.get("y_tickLabels_visible").asBoolean()).isTrue(); }
JavaKernelInfoHandler extends KernelHandler<Message> { @Override public void handle(Message message) { logger.debug("Processing kernel info request"); Message reply = new Message(); HashMap<String, Serializable> map = new HashMap<>(6); map.put("protocol_version", "5.0"); map.put("implementation", "java"); map.put("implementation_version", "1.0.0"); HashMap<String, Serializable> map1 = new HashMap<String, Serializable>(7); map1.put("name", "Java"); map1.put("version", System.getProperty("java.version")); map1.put("mimetype", ""); map1.put("file_extension", ".java"); map1.put("codemirror_mode", "text/x-java"); map1.put("nbconverter_exporter", ""); map.put("language_info", map1); map.put("banner", "BeakerX kernel for Java"); map.put("beakerx", true); map.put("help_links", new ArrayList<String>()); reply.setContent(map); reply.setHeader(new Header(KERNEL_INFO_REPLY, message.getHeader().getSession())); reply.setParentHeader(message.getHeader()); reply.setIdentities(message.getIdentities()); send(reply); } JavaKernelInfoHandler(KernelFunctionality kernel); @Override void handle(Message message); }
@Test public void handle_shouldSendMessage() throws Exception { handler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); } @Test public void handle_sentMessageHasContent() throws Exception { handler.handle(message); Message sentMessage = kernel.getSentMessages().get(0); Assertions.assertThat(sentMessage.getContent()).isNotEmpty(); } @Test public void handle_sentMessageHasHeaderTypeIsKernelInfoReply() throws Exception { handler.handle(message); Message sentMessage = kernel.getSentMessages().get(0); Header header = sentMessage.getHeader(); Assertions.assertThat(header).isNotNull(); Assertions.assertThat(header.getType()).isEqualTo(KERNEL_INFO_REPLY.getName()); } @Test public void handle_sentMessageHasLanguageInfo() throws Exception { handler.handle(message); Message sentMessage = kernel.getSentMessages().get(0); Map<String, Serializable> map = sentMessage.getContent(); Assertions.assertThat(map).isNotNull(); Assertions.assertThat(map.get("language_info")).isNotNull(); } @Test public void handle_messageContentHasJavaLabel() throws Exception { handler.handle(message); Message sentMessage = kernel.getSentMessages().get(0); Map<String, Serializable> map = sentMessage.getContent(); Assertions.assertThat(map).isNotNull(); Assertions.assertThat(map.get("implementation")).isEqualTo("java"); }
CategoryPointsSerializer extends CategoryGraphicsSerializer<CategoryPoints> { @Override public void serialize(CategoryPoints categoryPoints, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartObject(); super.serialize(categoryPoints, jgen, provider); if (categoryPoints.getSizes() != null) { jgen.writeObjectField("sizes", categoryPoints.getSizes()); } else { jgen.writeObjectField("size", categoryPoints.getSize()); } if (categoryPoints.getShapes() != null) { jgen.writeObjectField("shaps", categoryPoints.getShapes()); } else { jgen.writeObjectField("shape", categoryPoints.getShape()); } if (categoryPoints.getFills() != null) { jgen.writeObjectField("fills", categoryPoints.getFills()); } else { jgen.writeObjectField("fill", categoryPoints.getFill()); } if (categoryPoints.getOutlineColors() != null) { jgen.writeObjectField("outline_colors", categoryPoints.getOutlineColors()); } else { jgen.writeObjectField("outline_color", categoryPoints.getOutlineColor()); } jgen.writeEndObject(); } @Override void serialize(CategoryPoints categoryPoints, JsonGenerator jgen, SerializerProvider provider); }
@Test public void serializeSizeCategoryPoints_resultJsonHasSize() throws IOException { CategoryPoints categoryPoints = new CategoryPoints(); categoryPoints.setSize(11); categoryPointsSerializer.serialize(categoryPoints, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("size")).isTrue(); Assertions.assertThat(actualObj.get("size").asInt()).isEqualTo(11); } @Test public void serializeSizesCategoryPoints_resultJsonHasSizes() throws IOException { CategoryPoints categoryPoints = new CategoryPoints(); categoryPoints.setSize(Arrays.asList(11, 22, 33)); categoryPointsSerializer.serialize(categoryPoints, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("sizes")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("sizes"); Assertions.assertThat(arrayNode.get(1).asInt()).isEqualTo(22); } @Test public void serializeShapeCategoryPoints_resultJsonHasShape() throws IOException { CategoryPoints categoryPoints = new CategoryPoints(); categoryPoints.setShape(ShapeType.CIRCLE); categoryPointsSerializer.serialize(categoryPoints, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("shape")).isTrue(); Assertions.assertThat(actualObj.get("shape").asText()).isEqualTo("CIRCLE"); } @Test public void serializeShapesCategoryPoints_resultJsonHasShapes() throws IOException { CategoryPoints categoryPoints = new CategoryPoints(); categoryPoints.setShape(Arrays.asList(ShapeType.CIRCLE, ShapeType.TRIANGLE)); categoryPointsSerializer.serialize(categoryPoints, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("shaps")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("shaps"); Assertions.assertThat(arrayNode.get(1).asText()).isEqualTo("TRIANGLE"); } @Test public void serializeFillCategoryPoints_resultJsonHasFill() throws IOException { CategoryPoints categoryPoints = new CategoryPoints(); categoryPoints.setFill(true); categoryPointsSerializer.serialize(categoryPoints, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("fill")).isTrue(); Assertions.assertThat(actualObj.get("fill").asBoolean()).isTrue(); } @Test public void serializeFillsCategoryPoints_resultJsonHasFills() throws IOException { CategoryPoints categoryPoints = new CategoryPoints(); categoryPoints.setFill(Arrays.asList(false, true, false)); categoryPointsSerializer.serialize(categoryPoints, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("fills")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("fills"); Assertions.assertThat(arrayNode.get(1).asBoolean()).isTrue(); } @Test public void serializeOutlineColorCategoryPoints_resultJsonHasOutlineColor() throws IOException { CategoryPoints categoryPoints = new CategoryPoints(); categoryPoints.setOutlineColor(Color.GREEN); categoryPointsSerializer.serialize(categoryPoints, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("outline_color")).isTrue(); Assertions.assertThat(actualObj.get("outline_color").get("rgb").asInt()) .isEqualTo(Color.GREEN.getRGB()); } @Test public void serializeOutlineColorsCategoryPoints_resultJsonHasOutlineColors() throws IOException { CategoryPoints categoryPoints = new CategoryPoints(); categoryPoints.setOutlineColor(Arrays.asList(Color.BLUE, Color.GREEN, Color.BLACK)); categoryPointsSerializer.serialize(categoryPoints, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("outline_colors")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("outline_colors"); Assertions.assertThat(arrayNode.get(1).get("rgb").asInt()).isEqualTo(Color.GREEN.getRGB()); }
CategoryPlotSerializer extends AbstractChartSerializer<CategoryPlot> { @Override public void serialize(CategoryPlot categoryPlot, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartObject(); serialize(categoryPlot, jgen); List<String> categoryNames = categoryPlot.getCategoryNames(); if (categoryNames != null) { jgen.writeObjectField("categoryNames", categoryNames); } List<CategoryGraphics> categoryGraphicsList = categoryPlot.getGraphics(); if (categoryGraphicsList != null) { for (CategoryGraphics categoryGraphics : categoryGraphicsList) { categoryGraphics.createItemLabels(categoryPlot); } jgen.writeObjectField(GRAPHICS_LIST, categoryGraphicsList); } jgen.writeObjectField("orientation", categoryPlot.getOrientation()); jgen.writeObjectField("category_margin", categoryPlot.getCategoryMargin()); jgen.writeObjectField("categoryNamesLabelAngle", categoryPlot.getCategoryNamesLabelAngle()); jgen.writeEndObject(); } @Override void serialize(CategoryPlot categoryPlot, JsonGenerator jgen, SerializerProvider provider); static final String GRAPHICS_LIST; }
@Test public void serializeCategoryNamesOfCategoryPlot_resultJsonHasCategoryNames() throws IOException { CategoryPlot categoryPlot = new CategoryPlot(); categoryPlot.setCategoryNames(Arrays.asList("name1", "name2")); categoryPlotSerializer.serialize(categoryPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("categoryNames")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("categoryNames"); Assertions.assertThat(arrayNode.get(1).asText()).isEqualTo("name2"); } @Test public void serializeGraphicsListCategoryPlot_resultJsonHasGraphicsList() throws IOException { CategoryPlot categoryPlot = new CategoryPlot(); categoryPlot.add(Arrays.asList(new CategoryBars(), new CategoryPoints())); categoryPlotSerializer.serialize(categoryPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("graphics_list")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("graphics_list"); Assertions.assertThat(arrayNode.size()).isEqualTo(2); } @Test public void serializeOrientationCategoryPlot_resultJsonHasOrientation() throws IOException { CategoryPlot categoryPlot = new CategoryPlot(); categoryPlot.setOrientation(PlotOrientationType.VERTICAL); categoryPlotSerializer.serialize(categoryPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("orientation")).isTrue(); Assertions.assertThat(actualObj.get("orientation").asText()).isEqualTo("VERTICAL"); } @Test public void serializeCategoryMarginOfCategoryPlot_resultJsonHasCategoryMargin() throws IOException { CategoryPlot categoryPlot = new CategoryPlot(); categoryPlot.setCategoryMargin(0.5); categoryPlotSerializer.serialize(categoryPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("category_margin")).isTrue(); Assertions.assertThat(actualObj.get("category_margin").asDouble()).isEqualTo(0.5); } @Test public void serializeCategoryNamesLabelAngleOfCategoryPlot_resultJsonHasCategoryNamesLabelAngle() throws IOException { CategoryPlot categoryPlot = new CategoryPlot(); categoryPlot.setCategoryNamesLabelAngle(0.5); categoryPlotSerializer.serialize(categoryPlot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("categoryNamesLabelAngle")).isTrue(); Assertions.assertThat(actualObj.get("categoryNamesLabelAngle").asDouble()).isEqualTo(0.5); }
CrosshairSerializer extends JsonSerializer<Crosshair> { @Override public void serialize(Crosshair crosshair, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException { jgen.writeStartObject(); jgen.writeObjectField("type", crosshair.getClass().getSimpleName()); if (crosshair.getColor() instanceof Color) { jgen.writeObjectField("color", crosshair.getColor()); } if (crosshair.getStyle() != null) { jgen.writeObjectField("style", crosshair.getStyle().toString()); } if (crosshair.getWidth() != null) { jgen.writeObjectField("width", crosshair.getWidth()); } jgen.writeEndObject(); } @Override void serialize(Crosshair crosshair, JsonGenerator jgen, SerializerProvider sp); }
@Test public void serializeCrosshair_resultJsonHasType() throws IOException { Crosshair crosshair = new Crosshair(); crosshairSerializer.serialize(crosshair, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("type")).isTrue(); Assertions.assertThat(actualObj.get("type").asText()).isEqualTo("Crosshair"); } @Test public void serializeColorCrosshair_resultJsonHasColor() throws IOException { Crosshair crosshair = new Crosshair(); crosshair.setColor(Color.GREEN); crosshairSerializer.serialize(crosshair, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("color")).isTrue(); Assertions.assertThat(actualObj.get("color").get("rgb").asInt()) .isEqualTo(Color.GREEN.getRGB()); } @Test public void serializeStyleCrosshair_resultJsonHasStyle() throws IOException { Crosshair crosshair = new Crosshair(); crosshair.setStyle(StrokeType.DASH); crosshairSerializer.serialize(crosshair, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("style")).isTrue(); Assertions.assertThat(actualObj.get("style").asText()).isEqualTo("DASH"); } @Test public void serializeWidthCrosshair_resultJsonHasWidth() throws IOException { Crosshair crosshair = new Crosshair(); crosshair.setWidth(2f); crosshairSerializer.serialize(crosshair, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("width")).isTrue(); Assertions.assertThat(actualObj.get("width").asDouble()).isEqualTo(2.0); }
HeatMapSerializer extends AbstractChartSerializer<HeatMap> { @Override public void serialize(HeatMap heatmap, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException { jgen.writeStartObject(); serialize(heatmap, jgen); jgen.writeObjectField(GRAPHICS_LIST, heatmap.getData()); jgen.writeObjectField(COLOR, heatmap.getColor()); jgen.writeEndObject(); } @Override void serialize(HeatMap heatmap, JsonGenerator jgen, SerializerProvider sp); static final String GRAPHICS_LIST; static final String COLOR; }
@Test public void serializeDataOfHeatMap_resultJsonHasGraphicsList() throws IOException { HeatMap heatMap = new HeatMap(); heatMap.setData( new Integer[][] { new Integer[] {new Integer(1), new Integer(2)}, new Integer[] {new Integer(3), new Integer(4)} }); heatMapSerializer.serialize(heatMap, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("graphics_list")).isTrue(); Assertions.assertThat(actualObj.get("graphics_list")).isNotEmpty(); } @Test public void serializeColorOfHeatMap_resultJsonHasColor() throws IOException { HeatMap heatMap = new HeatMap(); heatMap.setColor(new GradientColor(Arrays.asList(Color.GREEN, Color.BLUE))); heatMapSerializer.serialize(heatMap, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("color")).isTrue(); Assertions.assertThat(actualObj.get("color").get("colors")).isNotEmpty(); }
CppCommOpenHandler extends CommOpenHandler { public Handler<Message>[] getKernelControlChanelHandlers(String targetName){ if(TargetNamesEnum.KERNEL_CONTROL_CHANNEL.getTargetName().equalsIgnoreCase(targetName)){ return (Handler<Message>[]) KERNEL_CONTROL_CHANNEL_HANDLERS; }else{ return (Handler<Message>[]) new Handler<?>[0]; } } CppCommOpenHandler(KernelFunctionality kernel); Handler<Message>[] getKernelControlChanelHandlers(String targetName); }
@Test public void getControlHandlersWithEmptyString_returnEmptyHandlersArray() throws Exception { Handler<Message>[] handlers = commOpenHandler.getKernelControlChanelHandlers(""); Assertions.assertThat(handlers).isEmpty(); } @Test public void getControlHandlersWithTargetName_returnNotEmptyHandlersArray() throws Exception { Handler<Message>[] handlers = commOpenHandler.getKernelControlChanelHandlers(targetName); Assertions.assertThat(handlers).isNotEmpty(); }
PointsSerializer extends XYGraphicsSerializer<Points> { @Override public void serialize(Points points, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException { jgen.writeStartObject(); super.serialize(points, jgen, sp); if (points.getSizes() != null) { jgen.writeObjectField("sizes", points.getSizes()); } else { jgen.writeObjectField("size", points.getSize()); } if (points.getShapes() != null) { jgen.writeObjectField("shaps", points.getShapes()); } else { jgen.writeObjectField("shape", points.getShape()); } if (points.getFills() != null) { jgen.writeObjectField("fills", points.getFills()); } else { jgen.writeObjectField("fill", points.getFill()); } if (points.getColors() != null) { jgen.writeObjectField("colors", points.getColors()); } else { jgen.writeObjectField("color", points.getColor()); } if (points.getOutlineColors() != null) { jgen.writeObjectField("outline_colors", points.getOutlineColors()); } else { jgen.writeObjectField("outline_color", points.getOutlineColor()); } jgen.writeEndObject(); } @Override void serialize(Points points, JsonGenerator jgen, SerializerProvider sp); }
@Test public void serializeSizePoints_resultJsonHasSize() throws IOException { points.setSize(new Integer(11)); pointsSerializer.serialize(points, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("size")).isTrue(); Assertions.assertThat(actualObj.get("size").asInt()).isEqualTo(11); } @Test public void serializeSizesPoints_resultJsonHasSizes() throws IOException { points.setSize(Arrays.asList(11, 22, 33)); pointsSerializer.serialize(points, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("sizes")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("sizes"); Assertions.assertThat(arrayNode.get(1).asInt()).isEqualTo(22); } @Test public void serializeShapePoints_resultJsonHasShape() throws IOException { points.setShape(ShapeType.CIRCLE); pointsSerializer.serialize(points, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("shape")).isTrue(); Assertions.assertThat(actualObj.get("shape").asText()).isEqualTo("CIRCLE"); } @Test public void serializeShapesPoints_resultJsonHasShapes() throws IOException { points.setShape(Arrays.asList(ShapeType.CIRCLE, ShapeType.CROSS)); pointsSerializer.serialize(points, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("shaps")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("shaps"); Assertions.assertThat(arrayNode.get(1).asText()).isEqualTo("CROSS"); } @Test public void serializeFillPoints_resultJsonHasFill() throws IOException { points.setFill(true); pointsSerializer.serialize(points, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("fill")).isTrue(); Assertions.assertThat(actualObj.get("fill").asBoolean()).isTrue(); } @Test public void serializeFillsPoints_resultJsonHasFills() throws IOException { points.setFill(Arrays.asList(false, true, false)); pointsSerializer.serialize(points, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("fills")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("fills"); Assertions.assertThat(arrayNode.get(1).asBoolean()).isTrue(); } @Test public void serializeColorPoints_resultJsonHasColor() throws IOException { points.setColor(Color.GREEN); pointsSerializer.serialize(points, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("color")).isTrue(); Assertions.assertThat(actualObj.get("color")).isNotEmpty(); } @Test public void serializeColorsPoints_resultJsonHasColors() throws IOException { points.setColor(Arrays.asList(Color.GREEN, Color.BLUE)); pointsSerializer.serialize(points, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("colors")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("colors"); Assertions.assertThat(arrayNode.get(1)).isNotEmpty(); } @Test public void serializeOutlineColorPoints_resultJsonHasOutlineColor() throws IOException { points.setOutlineColor(Color.GREEN); pointsSerializer.serialize(points, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("outline_color")).isTrue(); Assertions.assertThat(actualObj.get("outline_color").get("rgb").asInt()) .isEqualTo(Color.GREEN.getRGB()); } @Test public void serializeOutlineColorsPoints_resultJsonHasOutlineColors() throws IOException { points.setOutlineColor(Arrays.asList(Color.GREEN, Color.BLUE)); pointsSerializer.serialize(points, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("outline_colors")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("outline_colors"); Assertions.assertThat(arrayNode.get(1).get("rgb").asInt()).isEqualTo(Color.BLUE.getRGB()); }
GraphicsSerializer extends JsonSerializer<T> { @Override public void serialize(T graphics, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException { jgen.writeObjectField("type", graphics.getClass().getSimpleName()); jgen.writeObjectField("uid", graphics.getUid()); jgen.writeObjectField("visible", graphics.getVisible()); jgen.writeObjectField("yAxis", graphics.getYAxis()); jgen.writeObjectField("hasClickAction", graphics.hasClickAction()); if(StringUtils.isNotEmpty(graphics.getClickTag())) { jgen.writeObjectField("clickTag", graphics.getClickTag()); } Map<String, String> keyTags = graphics.getKeyTags(); if(keyTags != null && !keyTags.isEmpty()) { jgen.writeObjectField("keyTags", keyTags); } Object[] keys = graphics.getKeys(); if(ArrayUtils.isNotEmpty(keys)) { jgen.writeObjectField("keys", keys); } } @Override void serialize(T graphics, JsonGenerator jgen, SerializerProvider sp); }
@Test public void serializeLineGraphics_resultJsonHasType() throws IOException { Line line = new Line(); graphicsSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("type")).isTrue(); Assertions.assertThat(actualObj.get("type").asText()).isEqualTo("Line"); } @Test public void serializeLineGraphics_resultJsonHasUid() throws IOException { Line line = new Line(); graphicsSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("uid")).isTrue(); Assertions.assertThat(actualObj.get("uid")).isNotNull(); } @Test public void serializeVisibleLineGraphics_resultJsonHasVisible() throws IOException { Line line = new Line(); line.setVisible(true); graphicsSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("visible")).isTrue(); Assertions.assertThat(actualObj.get("visible").asBoolean()).isTrue(); } @Test public void serializeYAxisLineGraphics_resultJsonHasYAxis() throws IOException { Line line = new Line(); line.setyAxis("Y Axis name"); graphicsSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("yAxis")).isTrue(); Assertions.assertThat(actualObj.get("yAxis").asText()).isEqualTo("Y Axis name"); } @Test public void serializeClickActionLineGraphics_resultJsonHasClickAction() throws IOException { Line line = new Line(); line.onClick( new GraphicsActionListener() { @Override public void execute(GraphicsActionObject actionObject) {} }); graphicsSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("hasClickAction")).isTrue(); Assertions.assertThat(actualObj.get("hasClickAction").asBoolean()).isTrue(); } @Test public void serializeClickTagLineGraphics_resultJsonHasClickTag() throws IOException { Line line = new Line(); line.onClick("some click tag"); graphicsSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("clickTag")).isTrue(); Assertions.assertThat(actualObj.get("clickTag").asText()).isEqualTo("some click tag"); } @Test public void serializeKeyTagsLineGraphics_resultJsonHasKeyTags() throws IOException { Line line = new Line(); line.onKey("key01", "tag01"); graphicsSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("keyTags")).isTrue(); Assertions.assertThat(actualObj.get("keyTags")).isNotEmpty(); } @Test public void serializeKeysLineGraphics_resultJsonHasKeys() throws IOException { Line line = new Line(); line.onKey( "key01", new GraphicsActionListener() { @Override public void execute(GraphicsActionObject actionObject) {} }); graphicsSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("keys")).isTrue(); Assertions.assertThat(actualObj.get("keys")).isNotEmpty(); }
TreeMapNodeSerializer extends JsonSerializer<TreeMapNode> { @Override @SuppressWarnings("unchecked") public void serialize(TreeMapNode treeMapNode, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartObject(); jgen.writeObjectField("type", treeMapNode.getClass().getSimpleName()); jgen.writeObjectField("weight", treeMapNode.getWeight()); if (treeMapNode.getValue() != null) { jgen.writeObjectField("doubleValue", treeMapNode.getDoubleValue()); jgen.writeObjectField("labelValue", treeMapNode.getLabelValue()); Object userObject = treeMapNode.getUserObject(); Map<String, Object> values = (Map<String, Object>) userObject; jgen.writeObjectField("label", values.get("label")); jgen.writeObjectField("color", values.get("color")); jgen.writeObjectField("tooltip", values.get("tooltip")); } if (treeMapNode.getChildren() != null) jgen.writeObjectField("children", treeMapNode.getChildren()); jgen.writeEndObject(); } @Override @SuppressWarnings("unchecked") void serialize(TreeMapNode treeMapNode, JsonGenerator jgen, SerializerProvider provider); }
@Test public void serializeTreeMapNode_resultJsonHasType() throws IOException { TreeMapNode treeMapNode = new TreeMapNode("label"); treeMapNodeSerializer.serialize(treeMapNode, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("type")).isTrue(); Assertions.assertThat(actualObj.get("type").asText()).isEqualTo("TreeMapNode"); } @Test public void serializeWeightOfTreeMapNode_resultJsonHasWeight() throws IOException { TreeMapNode treeMapNode = new TreeMapNode("label"); treeMapNode.setWeight(0.5); treeMapNodeSerializer.serialize(treeMapNode, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("weight")).isTrue(); Assertions.assertThat(actualObj.get("weight").asDouble()).isEqualTo(0.5); } @Test public void serializeDoubleValueOfTreeMapNode_resultJsonHasDoubleValue() throws IOException { TreeMapNode treeMapNode = new TreeMapNode("010", 1, new DefaultValue(1.5)); treeMapNode.setUserObject(values); treeMapNodeSerializer.serialize(treeMapNode, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("doubleValue")).isTrue(); Assertions.assertThat(actualObj.get("doubleValue").asDouble()).isEqualTo(1.5); } @Test public void serializeLabelValueOfTreeMapNode_resultJsonHasLabelValue() throws IOException { TreeMapNode treeMapNode = new TreeMapNode("010", 1, new DefaultValue(1.5)); treeMapNode.setUserObject(values); treeMapNodeSerializer.serialize(treeMapNode, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("labelValue")).isTrue(); Assertions.assertThat(actualObj.get("labelValue").asText()).isEqualTo("1.5"); } @Test public void serializeLabelOfTreeMapNode_resultJsonHasLabel() throws IOException { TreeMapNode treeMapNode = new TreeMapNode("010", 1, new DefaultValue(1.5)); treeMapNode.setUserObject(values); treeMapNodeSerializer.serialize(treeMapNode, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("label")).isTrue(); Assertions.assertThat(actualObj.get("label").asText()).isEqualTo("some label"); } @Test public void serializeColorOfTreeMapNode_resultJsonHasColor() throws IOException { TreeMapNode treeMapNode = new TreeMapNode("010", 1, new DefaultValue(1.5)); treeMapNode.setUserObject(values); treeMapNodeSerializer.serialize(treeMapNode, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("color")).isTrue(); } @Test public void serializeTooltipOfTreeMapNode_resultJsonHasTooltip() throws IOException { TreeMapNode treeMapNode = new TreeMapNode("010", 1, new DefaultValue(1.5)); treeMapNode.setUserObject(values); treeMapNodeSerializer.serialize(treeMapNode, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("tooltip")).isTrue(); Assertions.assertThat(actualObj.get("tooltip").asText()).isEqualTo("some tooltip"); } @Test public void serializeChildrenOfTreeMapNode_resultJsonHasChildren() throws IOException { TreeMapNode treeMapNodeRoot = new TreeMapNode("001"); treeMapNodeRoot.add(new TreeMapNode("010", 1, new DefaultValue(1.5))); treeMapNodeRoot.add(new TreeMapNode("020", 2, new DefaultValue(2.5))); treeMapNodeSerializer.serialize(treeMapNodeRoot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("children")).isTrue(); Assertions.assertThat(actualObj.get("children")).isNotEmpty(); }
Message { public Header getHeader() { return header; } Message(); JupyterMessages type(); List<byte[]> getIdentities(); void setIdentities(List<byte[]> identities); Header getHeader(); void setHeader(Header header); Header getParentHeader(); void setParentHeader(Header parentHeader); Map<String, Serializable> getMetadata(); void setMetadata(Map<String, Serializable> metadata); Map<String, Serializable> getContent(); void setContent(Map<String, Serializable> content); @Override String toString(); }
@Test public void createMessageWithEmptyConstructor_messageHasHeaderIsNotNull() { Message message = new Message(); Assertions.assertThat(message.getHeader()).isNotNull(); }
ConstantLineSerializer extends JsonSerializer<ConstantLine> { @Override public void serialize(ConstantLine constantLine, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException { jgen.writeStartObject(); boolean isNanoPlot = NanoPlot.class.equals(constantLine.getPlotType()); jgen.writeObjectField("type", constantLine.getClass().getSimpleName()); jgen.writeObjectField("x", isNanoPlot ? processLargeNumber(constantLine.getX()) : constantLine.getX()); jgen.writeObjectField("y", constantLine.getY()); jgen.writeObjectField("visible", constantLine.getVisible()); jgen.writeObjectField("yAxis", constantLine.getYAxis()); jgen.writeObjectField("showLabel", constantLine.getShowLabel()); if (constantLine.getWidth() != null) { jgen.writeObjectField("width", constantLine.getWidth()); } if (constantLine.getStyle() != null) { jgen.writeObjectField("style", constantLine.getStyle().toString()); } if (constantLine.getColor() instanceof Color) { jgen.writeObjectField("color", constantLine.getColor()); } jgen.writeEndObject(); } @Override void serialize(ConstantLine constantLine, JsonGenerator jgen, SerializerProvider sp); }
@Test public void serializeConstantLine_resultJsonHasType() throws IOException { ConstantLine constantLine = new ConstantLine(); constantLineSerializer.serialize(constantLine, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("type")).isTrue(); Assertions.assertThat(actualObj.get("type").asText()).isEqualTo("ConstantLine"); } @Test public void serializeXConstantLine_resultJsonHasX() throws IOException { ConstantLine constantLine = new ConstantLine(); constantLine.setX(1); constantLineSerializer.serialize(constantLine, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("x")).isTrue(); Assertions.assertThat(actualObj.get("x").asInt()).isEqualTo(1); } @Test public void serializeBigIntXWithNanoPlotType_resultJsonHasStringX() throws IOException { ConstantLine constantLine = new ConstantLine(); constantLine.setX(new BigInteger("12345678901234567891000")); constantLine.setPlotType(NanoPlot.class); constantLineSerializer.serialize(constantLine, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("x")).isTrue(); Assertions.assertThat(actualObj.get("x").isTextual()).isTrue(); } @Test public void serializeYConstantLine_resultJsonHasY() throws IOException { ConstantLine constantLine = new ConstantLine(); constantLine.setY(1); constantLineSerializer.serialize(constantLine, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("y")).isTrue(); Assertions.assertThat(actualObj.get("y").asInt()).isEqualTo(1); } @Test public void serializeVisibleConstantLine_resultJsonHasVisible() throws IOException { ConstantLine constantLine = new ConstantLine(); constantLine.setVisible(true); constantLineSerializer.serialize(constantLine, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("visible")).isTrue(); Assertions.assertThat(actualObj.get("visible").asBoolean()).isTrue(); } @Test public void serializeYAxisConstantLine_resultJsonHasYAxis() throws IOException { ConstantLine constantLine = new ConstantLine(); constantLine.setyAxis("Y Axis name"); constantLineSerializer.serialize(constantLine, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("yAxis")).isTrue(); Assertions.assertThat(actualObj.get("yAxis").asText()).isEqualTo("Y Axis name"); } @Test public void serializeShowLabelConstantLine_resultJsonHasShowLabel() throws IOException { ConstantLine constantLine = new ConstantLine(); constantLine.setShowLabel(true); constantLineSerializer.serialize(constantLine, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("showLabel")).isTrue(); Assertions.assertThat(actualObj.get("showLabel").asBoolean()).isTrue(); } @Test public void serializeWidthConstantLine_resultJsonHasWidth() throws IOException { ConstantLine constantLine = new ConstantLine(); constantLine.setWidth(2f); constantLineSerializer.serialize(constantLine, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("width")).isTrue(); Assertions.assertThat(actualObj.get("width").asDouble()).isEqualTo(2.0); } @Test public void serializeStyleConstantLine_resultJsonHasStyle() throws IOException { ConstantLine constantLine = new ConstantLine(); constantLine.setStyle(StrokeType.SOLID); constantLineSerializer.serialize(constantLine, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("style")).isTrue(); Assertions.assertThat(actualObj.get("style").asText()).isEqualTo("SOLID"); } @Test public void serializeColorConstantLine_resultJsonHasColor() throws IOException { ConstantLine constantLine = new ConstantLine(); constantLine.setColor(Color.GREEN); constantLineSerializer.serialize(constantLine, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("color")).isTrue(); Assertions.assertThat(actualObj.get("color").get("rgb").asInt()) .isEqualTo(Color.GREEN.getRGB()); }
CompleteHandler extends KernelHandler<Message> { @Override public void handle(Message message) { wrapBusyIdle(kernel, message, () -> { handleMsg(message); }); } CompleteHandler(KernelFunctionality kernel); @Override void handle(Message message); static final String STATUS; static final String MATCHES; static final String CURSOR_END; static final String CURSOR_START; static final String CODE; static final String CURSOR_POS; }
@Test public void handle_shouldSendMessage() throws Exception { completeHandler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); Assertions.assertThat(kernel.getSentMessages().get(0)).isNotNull(); } @Test public void handle_sentMessageHasHeaderTypeIsCompleteReply() throws Exception { completeHandler.handle(message); Header header = kernel.getSentMessages().get(0).getHeader(); Assertions.assertThat(header).isNotNull(); Assertions.assertThat(header.getType()).isEqualTo(COMPLETE_REPLY.getName()); } @Test public void handle_messageContentHasCursorStartAndEndFields() throws Exception { completeHandler.handle(message); Map<String, Serializable> content = kernel.getSentMessages().get(0).getContent(); Assertions.assertThat(content.get(CompleteHandler.CURSOR_START)).isNotNull(); Assertions.assertThat(content.get(CompleteHandler.CURSOR_END)).isNotNull(); } @Test public void handle_messageContentHasMatchesField() throws Exception { completeHandler.handle(message); Map<String, Serializable> content = kernel.getSentMessages().get(0).getContent(); Assertions.assertThat(content.get(CompleteHandler.MATCHES)).isNotNull(); } @Test public void handle_messageContentHasStatus() throws Exception { completeHandler.handle(message); Map<String, Serializable> content = kernel.getSentMessages().get(0).getContent(); Assertions.assertThat(content.get(CompleteHandler.STATUS)).isNotNull(); }
TreeMapSerializer extends ChartSerializer<TreeMap> { @Override public void serialize(final TreeMap treeMap, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { TreeMapNode root = treeMap.getRoot(); process(root, new Visitor<TreeMapNode>() { @Override public void visit(TreeMapNode node) { Object userObject = node.getUserObject(); Map<String, Object> values; if (userObject instanceof Map) { values = (Map<String, Object>) userObject; if (node.isLeaf()) { Color color = treeMap.getColorProvider().getColor(node); values.put("color", toHex(color)); IToolTipBuilder toolTipBuilder = treeMap.getToolTipBuilder(); if (toolTipBuilder != null) { values.put("tooltip", toolTipBuilder.getToolTip(node)); } else { values.put("tooltip", values.get("label")); } } node.setUserObject(values); }else{ values = new HashMap<>(); values.put("label", userObject); IToolTipBuilder toolTipBuilder = treeMap.getToolTipBuilder(); if (toolTipBuilder != null) { values.put("tooltip", toolTipBuilder.getToolTip(node)); } else { values.put("tooltip", userObject); } } if (node.isLeaf()) { Color color = treeMap.getColorProvider().getColor(node); values.put("color", toHex(color)); } node.setUserObject(values); } }); jgen.writeStartObject(); serialize(treeMap, jgen); if (root != null) jgen.writeObjectField("graphics_list", root); if (treeMap.getMode() != null) jgen.writeObjectField("mode", treeMap.getMode().getJsName()); if (treeMap.getSticky() != null) jgen.writeObjectField("sticky", treeMap.getSticky()); if (treeMap.getRatio() != null) jgen.writeObjectField("ratio", treeMap.getRatio()); if (treeMap.getRound() != null) jgen.writeObjectField("round", treeMap.getRound()); jgen.writeObjectField("valueAccessor", treeMap.getValueAccessor()); jgen.writeEndObject(); } @Override void serialize(final TreeMap treeMap, JsonGenerator jgen, SerializerProvider provider); }
@Test public void serializeGraphicsListOfTreeMap_resultJsonHasGraphicsList() throws IOException { treeMapSerializer.serialize(treeMap, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("graphics_list")).isTrue(); } @Test public void serializeModeOfTreeMap_resultJsonHasMode() throws IOException { treeMap.setMode(Mode.DICE); treeMapSerializer.serialize(treeMap, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("mode")).isTrue(); Assertions.assertThat(actualObj.get("mode").asText()).isNotEmpty(); } @Test public void serializeStickyOfTreeMap_resultJsonHasSticky() throws IOException { treeMap.setSticky(true); treeMapSerializer.serialize(treeMap, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("sticky")).isTrue(); Assertions.assertThat(actualObj.get("sticky").asBoolean()).isTrue(); } @Test public void serializeRatioOfTreeMap_resultJsonHasRatio() throws IOException { treeMap.setRatio(2.0); treeMapSerializer.serialize(treeMap, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("ratio")).isTrue(); Assertions.assertThat(actualObj.get("ratio").asDouble()).isEqualTo(2.0); } @Test public void serializeRoundOfTreeMap_resultJsonHasRound() throws IOException { treeMap.setRound(true); treeMapSerializer.serialize(treeMap, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("round")).isTrue(); Assertions.assertThat(actualObj.get("round").asBoolean()).isTrue(); } @Test public void serializeValueAccessorOfTreeMap_resultJsonHasValueAccessor() throws IOException { treeMap.setValueAccessor(ValueAccessor.WEIGHT); treeMapSerializer.serialize(treeMap, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("valueAccessor")).isTrue(); Assertions.assertThat(actualObj.get("valueAccessor").asText()).isNotEmpty(); }
XYGraphicsSerializer extends GraphicsSerializer<T> { @Override public void serialize(T xyGraphics, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException { super.serialize(xyGraphics, jgen, sp); boolean isNanoPlot = NanoPlot.class.equals(xyGraphics.getPlotType()); jgen.writeObjectField("x", isNanoPlot ? processLargeNumbers(xyGraphics.getX()) : xyGraphics.getX()); jgen.writeObjectField("y", xyGraphics.getY()); jgen.writeObjectField(DISPLAY_NAME, xyGraphics.getDisplayName()); if (xyGraphics.getLodFilter() != null){ jgen.writeObjectField("lod_filter", xyGraphics.getLodFilter().getText()); } List<String> toolTips = xyGraphics.getToolTips(); if (toolTips != null) { jgen.writeObjectField("tooltips", toolTips); } } @Override void serialize(T xyGraphics, JsonGenerator jgen, SerializerProvider sp); static final String DISPLAY_NAME; }
@Test public void serializeXOfXYGraphicsLine_resultJsonHasX() throws IOException { line.setX(Arrays.asList(1, 2, 3)); xyGraphicsSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("x")).isTrue(); Assertions.assertThat(actualObj.get("x")).isNotEmpty(); } @Test public void serializeBigIntXWithNanoPlotType_resultJsonHasStringX() throws IOException { line.setX( Arrays.asList( new BigInteger("12345678901234567891000"), new BigInteger("12345678901234567891000"))); line.setPlotType(NanoPlot.class); xyGraphicsSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("x")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("x"); Assertions.assertThat(arrayNode.get(1).isTextual()).isTrue(); } @Test public void serializeYOfXYGraphicsLine_resultJsonHasY() throws IOException { line.setY(Arrays.asList(1, 2, 3)); xyGraphicsSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("y")).isTrue(); Assertions.assertThat(actualObj.get("y")).isNotEmpty(); } @Test public void serializeDisplayNameOfXYGraphicsLine_resultJsonHasDisplayName() throws IOException { line.setDisplayName("some display name"); xyGraphicsSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("display_name")).isTrue(); Assertions.assertThat(actualObj.get("display_name").asText()).isEqualTo("some display name"); } @Test public void serializeLodFilterOfXYGraphicsLine_resultJsonHasLodFilter() throws IOException { line.setLodFilter(Filter.LINE); xyGraphicsSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("lod_filter")).isTrue(); Assertions.assertThat(actualObj.get("lod_filter").asText()).isEqualTo("line"); } @Test public void serializeTooltipsOfXYGraphicsLine_resultJsonHastooltips() throws IOException { line.setToolTip(Arrays.asList("one", "two")); xyGraphicsSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("tooltips")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("tooltips"); Assertions.assertThat(arrayNode.get(1).asText()).isEqualTo("two"); }
CategoryLinesSerializer extends CategoryGraphicsSerializer<CategoryLines> { @Override public void serialize(CategoryLines categoryLines, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartObject(); super.serialize(categoryLines, jgen, provider); if (categoryLines.getWidth() != null) { jgen.writeObjectField("width", categoryLines.getWidth()); } if (categoryLines.getStyles() != null) { jgen.writeObjectField("styles", categoryLines.getStyles()); } else { jgen.writeObjectField("style", categoryLines.getStyle().toString()); } if (categoryLines.getInterpolation() != null) { jgen.writeObjectField("interpolation", categoryLines.getInterpolation()); } jgen.writeEndObject(); } @Override void serialize(CategoryLines categoryLines, JsonGenerator jgen, SerializerProvider provider); }
@Test public void serializeWidthCategoryLines_resultJsonHasWidth() throws IOException { CategoryLines categoryLines = new CategoryLines(); categoryLines.setWidth(11f); categoryLinesSerializer.serialize(categoryLines, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("width")).isTrue(); Assertions.assertThat(actualObj.get("width").asInt()).isEqualTo(11); } @Test public void serializeStrokeTypeStems_resultJsonHasStyle() throws IOException { CategoryLines categoryLines = new CategoryLines(); categoryLines.setStyle(StrokeType.SOLID); categoryLinesSerializer.serialize(categoryLines, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("style")).isTrue(); Assertions.assertThat(actualObj.get("style").asText()).isEqualTo("SOLID"); } @Test public void serializeStrokeTypeListStems_resultJsonHasStyles() throws IOException { CategoryLines categoryLines = new CategoryLines(); categoryLines.setStyle(Arrays.asList(StrokeType.SOLID, StrokeType.DASHDOT)); categoryLinesSerializer.serialize(categoryLines, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("styles")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("styles"); Assertions.assertThat(arrayNode.get(1).asText()).isEqualTo("DASHDOT"); } @Test public void serializeInterpolationCategoryLines_resultJsonHasInterpolation() throws IOException { CategoryLines categoryLines = new CategoryLines(); categoryLines.setInterpolation(1); categoryLinesSerializer.serialize(categoryLines, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("interpolation")).isTrue(); Assertions.assertThat(actualObj.get("interpolation").asInt()).isEqualTo(1); }
XYChartSerializer extends AbstractChartSerializer<XYChart> { @Override public void serialize(XYChart xychart, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException { jgen.writeStartObject(); serialize(xychart, jgen); jgen.writeObjectField(GRAPHICS_LIST, xychart.getGraphics()); jgen.writeObjectField("constant_lines", xychart.getConstantLines()); jgen.writeObjectField("constant_bands", xychart.getConstantBands()); jgen.writeObjectField("rasters", xychart.getRasters()); jgen.writeObjectField("texts", xychart.getTexts()); jgen.writeObjectField("x_auto_range", xychart.getXAutoRange()); jgen.writeObjectField("x_lower_bound", xychart.getXLowerBound()); jgen.writeObjectField("x_upper_bound", xychart.getXUpperBound()); jgen.writeObjectField("log_x", xychart.getLogX()); jgen.writeObjectField("x_log_base", xychart.getXLogBase()); if (xychart.getLodThreshold() != null) { jgen.writeObjectField(LOD_THRESHOLD, xychart.getLodThreshold()); } jgen.writeObjectField("x_tickLabels_visible", xychart.isxTickLabelsVisible()); jgen.writeObjectField("y_tickLabels_visible", xychart.isyTickLabelsVisible()); jgen.writeEndObject(); } @Override void serialize(XYChart xychart, JsonGenerator jgen, SerializerProvider sp); static final String GRAPHICS_LIST; static final String LOD_THRESHOLD; }
@Test public void serializeGraphicsOfXYChartPlot_resultJsonHasGraphicsList() throws IOException { Line line = new Line(); line.setX(Arrays.asList(1, 2, 3)); line.setY(Arrays.asList(2, 3, 4)); plot.add(line); xyChartSerializer.serialize(plot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("graphics_list")).isTrue(); Assertions.assertThat(actualObj.get("graphics_list")).isNotEmpty(); } @Test public void serializeConstantLinesOfXYChartPlot_resultJsonHasConstantLines() throws IOException { ConstantLine constantLine = new ConstantLine(); plot.add(constantLine); xyChartSerializer.serialize(plot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("constant_lines")).isTrue(); Assertions.assertThat(actualObj.get("constant_lines")).isNotEmpty(); } @Test public void serializeConstantBandsOfXYChartPlot_resultJsonHasConstantBands() throws IOException { ConstantBand constantBand = new ConstantBand(); plot.add(constantBand); xyChartSerializer.serialize(plot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("constant_bands")).isTrue(); Assertions.assertThat(actualObj.get("constant_bands")).isNotEmpty(); } @Test public void serializeTextsOfXYChartPlot_resultJsonHasTexts() throws IOException { plot.add(new Text()); xyChartSerializer.serialize(plot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("texts")).isTrue(); Assertions.assertThat(actualObj.get("texts")).isNotEmpty(); } @Test public void serializeXAutoRangeOfXYChartPlot_resultJsonHasXAutoRange() throws IOException { plot.setXAutoRange(true); xyChartSerializer.serialize(plot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("x_auto_range")).isTrue(); Assertions.assertThat(actualObj.get("x_auto_range").asBoolean()).isTrue(); } @Test public void serializeXLowerBoundOfXYChartPlot_resultJsonHasXLowerBound() throws IOException { plot.setXBound(0.5, 1.5); xyChartSerializer.serialize(plot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("x_lower_bound")).isTrue(); Assertions.assertThat(actualObj.get("x_lower_bound").asDouble()).isEqualTo(0.5); } @Test public void serializeXUpperBoundOfXYChartPlot_resultJsonHasXUpperBound() throws IOException { plot.setXBound(0.5, 1.5); xyChartSerializer.serialize(plot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("x_upper_bound")).isTrue(); Assertions.assertThat(actualObj.get("x_upper_bound").asDouble()).isEqualTo(1.5); } @Test public void serializeLogXOfXYChartPlot_resultJsonHasLogX() throws IOException { plot.setLogX(true); xyChartSerializer.serialize(plot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("log_x")).isTrue(); Assertions.assertThat(actualObj.get("log_x").asBoolean()).isTrue(); } @Test public void serializeXLogBaseOfXYChartPlot_resultJsonHasXLogBase() throws IOException { plot.setxLogBase(1.5); xyChartSerializer.serialize(plot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("x_log_base")).isTrue(); Assertions.assertThat(actualObj.get("x_log_base").asDouble()).isEqualTo(1.5); } @Test public void serializeLodThresholdOfXYChartPlot_resultJsonHasLodThreshold() throws IOException { plot.setLodThreshold(11); xyChartSerializer.serialize(plot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("lodThreshold")).isTrue(); Assertions.assertThat(actualObj.get("lodThreshold").asInt()).isEqualTo(11); } @Test public void serializeXTickLabelsVisibleOfXYChartPlot_resultJsonHasXTickLabelsVisible() throws IOException { plot.setxTickLabelsVisible(true); xyChartSerializer.serialize(plot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("x_tickLabels_visible")).isTrue(); Assertions.assertThat(actualObj.get("x_tickLabels_visible").asBoolean()).isTrue(); } @Test public void serializeYTickLabelsVisibleOfXYChartPlot_resultJsonHasYTickLabelsVisible() throws IOException { plot.setyTickLabelsVisible(true); xyChartSerializer.serialize(plot, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("y_tickLabels_visible")).isTrue(); Assertions.assertThat(actualObj.get("y_tickLabels_visible").asBoolean()).isTrue(); }
TextSerializer extends JsonSerializer<Text> { @Override public void serialize(Text text, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException { boolean isNanoPlot = NanoPlot.class.equals(text.getPlotType()); jgen.writeStartObject(); jgen.writeObjectField("type", text.getClass().getSimpleName()); jgen.writeObjectField("x", isNanoPlot ? processLargeNumber(text.getX()) : text.getX()); jgen.writeObjectField("y", text.getY()); jgen.writeObjectField("show_pointer", text.getShowPointer()); jgen.writeObjectField("text", text.getText()); jgen.writeObjectField("pointer_angle", text.getPointerAngle()); jgen.writeObjectField("color", text.getColor()); jgen.writeObjectField("size", text.getSize()); jgen.writeEndObject(); } @Override void serialize(Text text, JsonGenerator jgen, SerializerProvider sp); }
@Test public void serializeText_resultJsonHasType() throws IOException { textSerializer.serialize(text, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("type")).isTrue(); Assertions.assertThat(actualObj.get("type").asText()).isEqualTo("Text"); } @Test public void serializeXText_resultJsonHasX() throws IOException { text.setX(new Integer(11)); textSerializer.serialize(text, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("x")).isTrue(); Assertions.assertThat(actualObj.get("x").asInt()).isEqualTo(11); } @Test public void serializeBigIntXWithNanoPlotType_resultJsonHasStringX() throws IOException { text.setX(new BigInteger("12345678901234567891000")); text.setPlotType(NanoPlot.class); textSerializer.serialize(text, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("x")).isTrue(); Assertions.assertThat(actualObj.get("x").isTextual()).isTrue(); } @Test public void serializeYText_resultJsonHasY() throws IOException { text.setY(new Integer(22)); textSerializer.serialize(text, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("y")).isTrue(); Assertions.assertThat(actualObj.get("y").asInt()).isEqualTo(22); } @Test public void serializeShowPointerText_resultJsonHasShowPointer() throws IOException { text.setShowPointer(true); textSerializer.serialize(text, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("show_pointer")).isTrue(); Assertions.assertThat(actualObj.get("show_pointer").asBoolean()).isTrue(); } @Test public void serializeTextOfText_resultJsonHasText() throws IOException { text.setText("some text"); textSerializer.serialize(text, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("text")).isTrue(); Assertions.assertThat(actualObj.get("text").asText()).isEqualTo("some text"); } @Test public void serializePointerAngleOfText_resultJsonHasPointerAngle() throws IOException { text.setPointerAngle(0.5); textSerializer.serialize(text, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("pointer_angle")).isTrue(); Assertions.assertThat(actualObj.get("pointer_angle").asDouble()).isEqualTo(0.5); } @Test public void serializeColorOfText_resultJsonHasColor() throws IOException { text.setColor(Color.GREEN); textSerializer.serialize(text, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("color")).isTrue(); Assertions.assertThat(actualObj.get("color").get("rgb").asInt()) .isEqualTo(Color.GREEN.getRGB()); } @Test public void serializeSizeOfText_resultJsonHasSize() throws IOException { text.setSize(11); textSerializer.serialize(text, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("size")).isTrue(); Assertions.assertThat(actualObj.get("size").asInt()).isEqualTo(11); }
BarsSerializer extends BasedXYGraphicsSerializer<Bars> { @Override public void serialize(Bars bars, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException { jgen.writeStartObject(); super.serialize(bars, jgen, sp); if (bars.getWidths() != null) { jgen.writeObjectField("widths", bars.getWidths()); } else { jgen.writeObjectField("width", bars.getWidth()); } if (bars.getColors() != null) { jgen.writeObjectField("colors", bars.getColors()); } else { jgen.writeObjectField("color", bars.getColor()); } if (bars.getOutlineColors() != null) { jgen.writeObjectField("outline_colors", bars.getOutlineColors()); } else { jgen.writeObjectField("outline_color", bars.getOutlineColor()); } jgen.writeEndObject(); } @Override void serialize(Bars bars, JsonGenerator jgen, SerializerProvider sp); }
@Test public void serializeWidthBars_resultJsonHasWidth() throws IOException { Bars bars = new Bars(); bars.setWidth(11); barsSerializer.serialize(bars, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("width")).isTrue(); Assertions.assertThat(actualObj.get("width").asInt()).isEqualTo(11); } @Test public void serializeWidthsBars_resultJsonHasWidths() throws IOException { Bars bars = new Bars(); bars.setWidth(Arrays.asList(11, 22, 33)); barsSerializer.serialize(bars, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("widths")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("widths"); Assertions.assertThat(arrayNode.get(1).asInt()).isEqualTo(22); } @Test public void serializeColorBars_resultJsonHasColor() throws IOException { Bars bars = new Bars(); bars.setColor(Color.GREEN); barsSerializer.serialize(bars, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("color")).isTrue(); Assertions.assertThat(actualObj.get("color").get("rgb").asInt()) .isEqualTo(Color.GREEN.getRGB()); } @Test public void serializeColorsBars_resultJsonHasColors() throws IOException { Bars bars = new Bars(); bars.setColor(Arrays.asList(Color.BLUE, Color.GREEN, Color.BLACK)); barsSerializer.serialize(bars, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("colors")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("colors"); Assertions.assertThat(arrayNode.get(1).get("rgb").asInt()).isEqualTo(Color.GREEN.getRGB()); } @Test public void serializeOutlineColorBars_resultJsonHasOutlineColor() throws IOException { Bars bars = new Bars(); bars.setOutlineColor(Color.GREEN); barsSerializer.serialize(bars, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("outline_color")).isTrue(); Assertions.assertThat(actualObj.get("outline_color").get("rgb").asInt()) .isEqualTo(Color.GREEN.getRGB()); } @Test public void serializeOutlineColorsBars_resultJsonHasOutlineColors() throws IOException { Bars bars = new Bars(); bars.setOutlineColor(Arrays.asList(Color.BLUE, Color.GREEN, Color.BLACK)); barsSerializer.serialize(bars, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("outline_colors")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("outline_colors"); Assertions.assertThat(arrayNode.get(1).get("rgb").asInt()).isEqualTo(Color.GREEN.getRGB()); }
DisplayOutputContainer { public static void display(OutputContainer container) { if (container.getLayoutManager() instanceof TabbedOutputContainerLayoutManager) { List<CommFunctionality> items = container.getItems().stream().map(x -> toCommFunctionality(x)).collect(Collectors.toList()); Tab tab = new Tab(items, container.getLabels()); tab.display(); } else { container.getItems().forEach(item -> toCommFunctionality(item).display()); } } static void display(OutputContainer container); }
@Test public void shouldAddMapToOutputContainerTest() throws Exception { List<Map<String, Object>> values = ResourceLoaderTest.readAsList("tableRowsTest.csv"); OutputContainer oc = new OutputContainer(); oc.leftShift(values.get(0)); DisplayOutputContainer.display(oc); verifyMap(groovyKernel.getPublishedMessages()); } @Test public void shouldDisplayOutputContainerWithTabLayoutTest() throws Exception { List<Map<String, Object>> values = ResourceLoaderTest.readAsList("tableRowsTest.csv"); OutputContainer oc = new OutputContainer(); SimpleTimePlot simpleTimePlot = new SimpleTimePlot(values, Arrays.asList("m3", "y1")); oc.setLayoutManager(new TabbedOutputContainerLayoutManager()); oc.addItem(simpleTimePlot, "Scatter with History"); DisplayOutputContainer.display(oc); verifyTabLayout(groovyKernel.getPublishedMessages()); }
GradientColorSerializer extends JsonSerializer<GradientColor> { @Override public void serialize(GradientColor gradientColor, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException { jgen.writeObject(gradientColor.getColors()); } @Override void serialize(GradientColor gradientColor, JsonGenerator jgen, SerializerProvider sp); }
@Test public void serializeGradientColor_resultJsonHasGradientColor() throws IOException { GradientColor gradientColor = new GradientColor(Arrays.asList(Color.GREEN, Color.BLUE)); gradientColorSerializer.serialize(gradientColor, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); ArrayNode arrayNode = (ArrayNode) mapper.readTree(sw.toString()); Assertions.assertThat(arrayNode).isNotEmpty(); Assertions.assertThat(arrayNode.get(0).get("rgb").asInt()).isEqualTo(Color.GREEN.getRGB()); }
ConstantBandSerializer extends JsonSerializer<ConstantBand> { @Override public void serialize(ConstantBand constantBand, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException { jgen.writeStartObject(); boolean isNanoPlot = NanoPlot.class.equals(constantBand.getPlotType()); jgen.writeObjectField("type", constantBand.getClass().getSimpleName()); jgen.writeObjectField("x", isNanoPlot ? processLargeNumbers(constantBand.getX()) : constantBand.getX()); jgen.writeObjectField("y", constantBand.getY()); jgen.writeObjectField("visible", constantBand.getVisible()); jgen.writeObjectField("yAxis", constantBand.getYAxis()); if (constantBand.getColor() == null){ jgen.writeObjectField("color", new Color(0, 127, 255, 127)); }else{ jgen.writeObjectField("color", constantBand.getColor()); } jgen.writeEndObject(); } @Override void serialize(ConstantBand constantBand, JsonGenerator jgen, SerializerProvider sp); }
@Test public void serializeConstantBand_resultJsonHasType() throws IOException { ConstantBand constantBand = new ConstantBand(); constantBandSerializer.serialize(constantBand, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("type")).isTrue(); Assertions.assertThat(actualObj.get("type").asText()).isEqualTo("ConstantBand"); } @Test public void serializeXConstantBand_resultJsonHasX() throws IOException { ConstantBand constantBand = new ConstantBand(); constantBand.setX(Arrays.asList(1, 2, 3)); constantBandSerializer.serialize(constantBand, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("x")).isTrue(); Assertions.assertThat(actualObj.get("x")).isNotEmpty(); } @Test public void serializeBigIntXWithNanoPlotType_resultJsonHasStringXs() throws IOException { ConstantBand constantBand = new ConstantBand(); constantBand.setX( Arrays.asList( new BigInteger("12345678901234567891000"), new BigInteger("12345678901234567892000"))); constantBand.setPlotType(NanoPlot.class); constantBandSerializer.serialize(constantBand, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("x")).isTrue(); ArrayNode arrayNode = (ArrayNode) actualObj.get("x"); Assertions.assertThat(arrayNode.get(0).isTextual()).isTrue(); } @Test public void serializeYConstantBand_resultJsonHasY() throws IOException { ConstantBand constantBand = new ConstantBand(); constantBand.setY(Arrays.asList(1, 2, 3)); constantBandSerializer.serialize(constantBand, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("y")).isTrue(); Assertions.assertThat(actualObj.get("y")).isNotEmpty(); } @Test public void serializeVisibleConstantBand_resultJsonHasVisible() throws IOException { ConstantBand constantBand = new ConstantBand(); constantBand.setVisible(true); constantBandSerializer.serialize(constantBand, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("visible")).isTrue(); Assertions.assertThat(actualObj.get("visible").asBoolean()).isTrue(); } @Test public void serializeYAxisConstantBand_resultJsonHasYAxis() throws IOException { ConstantBand constantBand = new ConstantBand(); constantBand.setyAxis("Y Axis name"); constantBandSerializer.serialize(constantBand, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("yAxis")).isTrue(); Assertions.assertThat(actualObj.get("yAxis").asText()).isEqualTo("Y Axis name"); } @Test public void serializeColorConstantBand_resultJsonHasColor() throws IOException { ConstantBand constantBand = new ConstantBand(); constantBand.setColor(Color.GREEN); constantBandSerializer.serialize(constantBand, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("color")).isTrue(); Assertions.assertThat(actualObj.get("color").get("rgb").asInt()) .isEqualTo(Color.GREEN.getRGB()); }
LegendPositionSerializer extends JsonSerializer<LegendPosition> { @Override public void serialize(LegendPosition legendPosition, JsonGenerator jgen, SerializerProvider sp) throws IOException, JsonProcessingException { jgen.writeStartObject(); jgen.writeObjectField("type", legendPosition.getClass().getSimpleName()); if (legendPosition.getPosition() != null) { jgen.writeObjectField("position", legendPosition.getPosition().name()); }else{ jgen.writeObjectField("x", legendPosition.getX()); jgen.writeObjectField("y", legendPosition.getY()); } jgen.writeEndObject(); } @Override void serialize(LegendPosition legendPosition, JsonGenerator jgen, SerializerProvider sp); }
@Test public void serializeLegendPosition_resultJsonHasType() throws IOException { legendPositionSerializer.serialize(legendPosition, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("type")).isTrue(); Assertions.assertThat(actualObj.get("type").asText()).isEqualTo("LegendPosition"); } @Test public void serializePositionOfLegendPosition_resultJsonHasPosition() throws IOException { legendPosition.setPosition(LegendPosition.Position.LEFT); legendPositionSerializer.serialize(legendPosition, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("position")).isTrue(); Assertions.assertThat(actualObj.get("position").asText()).isEqualTo("LEFT"); } @Test public void serializeXLegendPosition_resultJsonHasX() throws IOException { LegendPosition legendPositionX = new LegendPosition(new int[] {11, 22}); legendPositionSerializer.serialize(legendPositionX, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("x")).isTrue(); Assertions.assertThat(actualObj.get("x").asInt()).isEqualTo(11); } @Test public void serializeYLegendPosition_resultJsonHasY() throws IOException { LegendPosition legendPositionY = new LegendPosition(new int[] {11, 22}); legendPositionSerializer.serialize(legendPositionY, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("y")).isTrue(); Assertions.assertThat(actualObj.get("y").asInt()).isEqualTo(22); }
GradientColor implements Serializable { public Color[] getColors() { return colors; } protected GradientColor(Color[] colors); GradientColor(List<Object> colors); Color[] getColors(); final static GradientColor BROWN_RED_YELLOW; final static GradientColor GREEN_YELLOW_WHITE; final static GradientColor WHITE_BLUE; }
@Test public void createGradientColorWithArrayBeakerColorParam_hasArrayBeakerColorsIsNotEmpty() { GradientColor gradientColor = new GradientColor(new Color[] {Color.black, Color.blue}); Assertions.assertThat(gradientColor.getColors()[0] instanceof Color).isTrue(); Assertions.assertThat(gradientColor.getColors()[1] instanceof Color).isTrue(); } @Test public void createGradientColorWithArraylistAwtColorParam_hasArrayBeakerColorsIsNotEmpty() { GradientColor gradientColor = new GradientColor(Arrays.asList(java.awt.Color.GREEN, java.awt.Color.BLUE)); Assertions.assertThat(gradientColor.getColors()[0] instanceof Color).isTrue(); Assertions.assertThat(gradientColor.getColors()[1] instanceof Color).isTrue(); }
CategoryPlot extends AbstractChart implements InternalCommWidget, InternalPlot { public PlotOrientationType getOrientation() { return orientation; } CategoryPlot(); @Override String getModelNameValue(); @Override String getViewNameValue(); @Override Comm getComm(); @Override void close(); CategoryPlot leftShift(CategoryGraphics graphics); List<CategoryGraphics> getGraphics(); CategoryPlot add(CategoryGraphics graphics); CategoryPlot add(List items); List<String> getCategoryNames(); CategoryPlot setCategoryNames(List<String> categoryNames); List<CategoryGraphics> getCategoryGraphics(); PlotOrientationType getOrientation(); void setOrientation(PlotOrientationType orientation); double getCategoryMargin(); void setCategoryMargin(double categoryMargin); double getCategoryNamesLabelAngle(); void setCategoryNamesLabelAngle(double categoryNamesLabelAngle); }
@Test public void createCategoryPlotByEmptyConstructor_hasVerticalOrientation() { CategoryPlot categoryPlot = new CategoryPlot(); Assertions.assertThat(categoryPlot.getOrientation()).isEqualTo(PlotOrientationType.VERTICAL); }
CategoryLines extends CategoryGraphics { public Float getWidth() { return this.width; } void setWidth(Float width); Float getWidth(); void setStyle(Object style); StrokeType getStyle(); List<StrokeType> getStyles(); void setInterpolation(Integer interpolation); Integer getInterpolation(); }
@Test public void createCategoryLinesByEmptyConstructor_hasWidthIsNotNull() { CategoryLines categoryLines = new CategoryLines(); Assertions.assertThat(categoryLines.getWidth()).isNotNull(); }
CategoryPoints extends CategoryGraphics { public float getSize() { return this.baseSize; } void setSize(Object size); float getSize(); List<Number> getSizes(); void setShape(Object shape); ShapeType getShape(); List<ShapeType> getShapes(); void setFill(Object fill); Boolean getFill(); List<Boolean> getFills(); void setOutlineColor(Object color); Color getOutlineColor(); List<Object> getOutlineColors(); }
@Test public void createCategoryPointsByEmptyConstructor_hasSizeGreaterThanZero() { CategoryPoints categoryPoints = new CategoryPoints(); Assertions.assertThat(categoryPoints.getSize()).isGreaterThan(0); }
CategoryStems extends CategoryGraphics { public Float getWidth() { return this.width; } void setBase(Object base); Number getBase(); List<Number> getBases(); void setWidth(Float width); Float getWidth(); void setStyle(Object style); StrokeType getStyle(); List<StrokeType> getStyles(); }
@Test public void createCategoryStemsByEmptyConstructor_hasWidthGreaterThanZero() { CategoryStems categoryStems = new CategoryStems(); Assertions.assertThat(categoryStems.getWidth()).isGreaterThan(0); }
CategoryBars extends CategoryGraphics { public Number getBase() { return this.baseBase; } void setBase(Object base); Number getBase(); List<Number> getBases(); void setWidth(Object width); Number getWidth(); List<Number> getWidths(); void setOutlineColor(Object color); Color getOutlineColor(); List<Object> getOutlineColors(); void setFill(Object fill); Boolean getFill(); List<Boolean> getFills(); void setDrawOutline(Object outline); List<Boolean> getDrawOutlines(); Boolean getDrawOutline(); LabelPositionType getLabelPosition(); void setLabelPosition(LabelPositionType labelPosition); }
@Test public void createCategoryBarsByEmptyConstructor_hasBaseBaseEqualsZero() { CategoryBars categoryBars = new CategoryBars(); Assertions.assertThat(categoryBars.getBase()).isEqualTo(0.0); }
XYStacker { public static List<BasedXYGraphics> stack(List<BasedXYGraphics> graphicsList) { return transformGraphicsList(graphicsList); } static List<BasedXYGraphics> stack(List<BasedXYGraphics> graphicsList); }
@Test public void callStackWithMaxSizeAreasIsThree_returnAllAreasWithSizeIsThree() { List<BasedXYGraphics> list = XYStacker.stack(Arrays.asList(area1, area2, area3)); Assertions.assertThat(list.get(0).getX().size()).isEqualTo(3); Assertions.assertThat(list.get(0).getY().size()).isEqualTo(3); Assertions.assertThat(list.get(1).getX().size()).isEqualTo(3); Assertions.assertThat(list.get(1).getY().size()).isEqualTo(3); Assertions.assertThat(list.get(2).getX().size()).isEqualTo(3); Assertions.assertThat(list.get(2).getY().size()).isEqualTo(3); } @Test public void callStackWithOneAndThreeElementsArea_returnFirstAreaWithTheSameYs() { List<BasedXYGraphics> list = XYStacker.stack(Arrays.asList(area1, area3)); List<Number> firstAreaYs = list.get(0).getY(); Assertions.assertThat(firstAreaYs.get(0)) .isEqualTo(firstAreaYs.get(1)) .isEqualTo(firstAreaYs.get(2)); } @Test public void callStackWithAreas_returnFirstAreaYsEqualsSecondAreaBases() { List<BasedXYGraphics> list = XYStacker.stack(Arrays.asList(area3, area1)); List<Number> firstAreaYs = list.get(0).getY(); List<Number> secondAreaBases = list.get(1).getBases(); Assertions.assertThat(firstAreaYs.get(0)).isEqualTo(secondAreaBases.get(0)); Assertions.assertThat(firstAreaYs.get(1)).isEqualTo(secondAreaBases.get(1)); Assertions.assertThat(firstAreaYs.get(2)).isEqualTo(secondAreaBases.get(2)); }
SelectMultiple extends MultipleSelectionWidget { public SelectMultiple() { super(); openComm(); } SelectMultiple(); @Override String getModelNameValue(); @Override String getViewNameValue(); static String VIEW_NAME_VALUE; static String MODEL_NAME_VALUE; }
@Test public void shouldSendCommMsgWhenValueChange() throws Exception { SelectMultiple widget = selectMultiple(); widget.setOptions(new String[]{"1","2", "3"}); kernel.clearPublishedMessages(); widget.setValue(new String[]{"2", "3"}); verifyMsgForProperty(kernel, SelectMultiple.VALUE, new String[]{"2", "3"}); } @Test public void shouldSendCommMsgWhenOptionsChange() throws Exception { SelectMultiple widget = selectMultiple(); widget.setOptions(new String[]{"2", "3"}); verifyMsgForProperty(kernel, SelectMultiple.OPTIONS_LABELS, new String[]{"2", "3"}); }
Crosshair implements Serializable { public StrokeType getStyle() { return this.style; } Crosshair setStyle(StrokeType style); StrokeType getStyle(); Crosshair setWidth(float width); Float getWidth(); Crosshair setColor(Object color); Color getColor(); @Override Object clone(); }
@Test public void createCrosshairByEmptyConstructor_hasStrokeTypeIsNull() { Crosshair crosshair = new Crosshair(); Assertions.assertThat(crosshair.getStyle()).isNull(); }
Area extends BasedXYGraphics { public Integer getInterpolation() { return this.interpolation; } void setInterpolation(Integer interpolation); Integer getInterpolation(); }
@Test public void createAreaByEmptyConstructor_hasInterpolationIsNull() { Area area = new Area(); Assertions.assertThat(area.getInterpolation()).isNull(); }
Area extends BasedXYGraphics { public void setInterpolation(Integer interpolation) { if (interpolation.intValue() < 0 || interpolation.intValue() > 1) { throw new IllegalArgumentException( "Area interpolation is limited to 0, 1"); } this.interpolation = interpolation; } void setInterpolation(Integer interpolation); Integer getInterpolation(); }
@Test(expected = IllegalArgumentException.class) public void setInterpolationWithPositive2_throwIllegalArgumentException() { Area area = new Area(); area.setInterpolation(new Integer(-2)); } @Test(expected = IllegalArgumentException.class) public void setInterpolationWithNegative2_throwIllegalArgumentException() { Area area = new Area(); area.setInterpolation(new Integer(2)); }
Text implements Serializable, Cloneable { public int getSize() { return size; } Number getX(); void setX(Object x); Number getY(); void setY(Number y); Boolean getShowPointer(); void setShowPointer(boolean showPointer); String getText(); void setText(String text); Double getPointerAngle(); void setPointerAngle(Double pointerAngle); Color getColor(); void setColor(Color color); int getSize(); void setSize(int size); Class getPlotType(); void setPlotType(Class plotType); @Override Object clone(); }
@Test public void createTextByEmptyConstructor_hasSizeValueGreaterThanZero() { Text text = new Text(); Assertions.assertThat(text.getSize()).isGreaterThan(0); }
Stems extends BasedXYGraphics { public void setStyle(Object style) { if (style instanceof StrokeType) { this.baseStyle = (StrokeType) style; } else if (style instanceof List) { @SuppressWarnings("unchecked") List<StrokeType> ss = (List<StrokeType>) style; setStyles(ss); } else { throw new IllegalArgumentException( "setStyle takes ShapeType or List of ShapeType"); } } void setWidth(Float width); Float getWidth(); void setStyle(Object style); StrokeType getStyle(); List<StrokeType> getStyles(); }
@Test(expected = IllegalArgumentException.class) public void setStyleWithShapeTypeParam_throwIllegalArgumentException() { Stems stems = new Stems(); stems.setStyle(ShapeType.DEFAULT); }
Line extends XYGraphics { public StrokeType getStyle() { return this.style; } Line(); Line(List<Number> ys); Line(List<Object> xs, List<Number> ys); void setWidth(Float width); Float getWidth(); void setStyle(StrokeType style); StrokeType getStyle(); void setInterpolation(Integer interpolation); Integer getInterpolation(); }
@Test public void createLineByEmptyConstructor_lineHasStyleIsNull() { Line line = new Line(); Assertions.assertThat(line.getStyle()).isNull(); }
TimePlot extends XYChart implements InternalCommWidget, InternalPlot { public XYChart setXBound(Date lower, Date upper) { setXBound((double) lower.getTime(), (double) upper.getTime()); return this; } TimePlot(); @Override String getModelNameValue(); @Override String getViewNameValue(); @Override Comm getComm(); @Override void close(); XYChart setXBound(Date lower, Date upper); @Override XYChart setXBound(List bound); }
@Test public void setXBoundWithTwoDatesParams_shouldSetXBoundParams() { TimePlot timePlot = new TimePlot(); timePlot.setXBound(lowerBound, upperBound); Assertions.assertThat(timePlot.getXLowerBound()).isGreaterThan(0); Assertions.assertThat(timePlot.getXUpperBound()).isGreaterThan(0); Assertions.assertThat(timePlot.getXAutoRange()).isFalse(); } @Test public void setXBoundWithListParam_shouldSetXBoundParams() { TimePlot timePlot = new TimePlot(); timePlot.setXBound(Arrays.asList(lowerBound, upperBound)); Assertions.assertThat(timePlot.getXLowerBound()).isGreaterThan(0); Assertions.assertThat(timePlot.getXUpperBound()).isGreaterThan(0); Assertions.assertThat(timePlot.getXAutoRange()).isFalse(); }
Histogram extends AbstractChart implements InternalCommWidget, InternalPlot { public DisplayMode getDisplayMode() { return displayMode; } Histogram(); @Override String getModelNameValue(); @Override String getViewNameValue(); @Override Comm getComm(); @Override void close(); Integer getRangeMin(); void setRangeMin(Integer rangeMin); Integer getRangeMax(); void setRangeMax(Integer rangeMax); int getBinCount(); void setBinCount(int binCount); boolean getRightClose(); void setRightClose(boolean rightClose); boolean getCumulative(); void setCumulative(boolean cumulative); boolean getNormed(); void setNormed(boolean normed); DisplayMode getDisplayMode(); void setDisplayMode(DisplayMode displayMode); boolean getLog(); void setLog(boolean log); @SuppressWarnings("unchecked") void setColor(Object color); List<Color> getColors(); Color getColor(); @SuppressWarnings("unchecked") void setData(Object data); List<Number> getData(); List<List<Number>> getListData(); List<String> getNames(); void setNames(List<String> names); }
@Test public void createHistogramByEmptyConstructor_hasDisplayModeIsNotNull() { Histogram histogram = new Histogram(); Assertions.assertThat(histogram.getDisplayMode()).isNotNull(); }
GradientColorProvider extends ColorProvider { @Override public Color getColor(TreeMapNode node) { double value = getValue(node); float result = (float) ((value - minValue) / (maxValue - minValue)); return ColorUtils.interpolateColor(start, end, result); } GradientColorProvider(TreeMap treeMap, Color start, Color end); GradientColorProvider(TreeMap treeMap); @Override Color getColor(TreeMapNode node); }
@Test public void createProviderWithTreeMapParam_getColorWithNodeReturnBeakerColorWithRGB() { GradientColorProvider gradientColorProvider = new GradientColorProvider(treeMap); Assertions.assertThat(gradientColorProvider.getColor(treeMap.getRoot()).getRGB()).isNotZero(); Assertions.assertThat(gradientColorProvider.getColor(node01).getRGB()).isNotZero(); } @Test public void createProviderWithTreeMapAndTwoColorsParams_getColorWithNodeReturnBeakerColorWithRGB() { GradientColorProvider gradientColorProvider = new GradientColorProvider(treeMap, Color.BLUE, Color.GREEN); Assertions.assertThat(gradientColorProvider.getColor(treeMap.getRoot()).getRGB()).isNotZero(); Assertions.assertThat(gradientColorProvider.getColor(node01).getRGB()).isNotZero(); }
RandomColorProvider extends ColorProvider { @Override public Color getColor(TreeMapNode node) { Object value; if (groupByParent && node.getParent() instanceof TreeMapNode){ value = ((TreeMapNode) node.getParent()).getLabel(); }else{ value = getValue(node); } if (!this.mapping.containsKey(value)) { mapping.put(value, colours[this.cursor]); cursor++; if (this.cursor == colours.length) { cursor = 0; } } return mapping.get(value); } RandomColorProvider(); RandomColorProvider(final Color[] colours); RandomColorProvider(List<Object> colors); @Override Color getColor(TreeMapNode node); boolean isGroupByParent(); void setGroupByParent(boolean groupByParent); }
@Test public void createProviderWithEmptyConstructor_getColorWithNodeReturnBeakerColorWithRGB() { RandomColorProvider randomColorProvider = new RandomColorProvider(); Assertions.assertThat(randomColorProvider.getColor(node01).getRGB()).isNotZero(); Assertions.assertThat(randomColorProvider.getColor(node02).getRGB()).isNotZero(); } @Test public void createProviderWithColorArrayParam_getColorWithNodeReturnBeakerColorWithRGB() { RandomColorProvider randomColorProvider = new RandomColorProvider(new Color[] {Color.BLUE, Color.GREEN}); Assertions.assertThat(randomColorProvider.getColor(node01).getRGB()).isNotZero(); Assertions.assertThat(randomColorProvider.getColor(node02).getRGB()).isNotZero(); }
ColorUtils { public static Color interpolateColor(final java.awt.Color COLOR1, final java.awt.Color COLOR2, float fraction) { final float INT_TO_FLOAT_CONST = 1f / 255f; fraction = Math.min(fraction, 1f); fraction = Math.max(fraction, 0f); final float RED1 = COLOR1.getRed() * INT_TO_FLOAT_CONST; final float GREEN1 = COLOR1.getGreen() * INT_TO_FLOAT_CONST; final float BLUE1 = COLOR1.getBlue() * INT_TO_FLOAT_CONST; final float ALPHA1 = COLOR1.getAlpha() * INT_TO_FLOAT_CONST; final float RED2 = COLOR2.getRed() * INT_TO_FLOAT_CONST; final float GREEN2 = COLOR2.getGreen() * INT_TO_FLOAT_CONST; final float BLUE2 = COLOR2.getBlue() * INT_TO_FLOAT_CONST; final float ALPHA2 = COLOR2.getAlpha() * INT_TO_FLOAT_CONST; final float DELTA_RED = RED2 - RED1; final float DELTA_GREEN = GREEN2 - GREEN1; final float DELTA_BLUE = BLUE2 - BLUE1; final float DELTA_ALPHA = ALPHA2 - ALPHA1; float red = RED1 + (DELTA_RED * fraction); float green = GREEN1 + (DELTA_GREEN * fraction); float blue = BLUE1 + (DELTA_BLUE * fraction); float alpha = ALPHA1 + (DELTA_ALPHA * fraction); red = Math.min(red, 1f); red = Math.max(red, 0f); green = Math.min(green, 1f); green = Math.max(green, 0f); blue = Math.min(blue, 1f); blue = Math.max(blue, 0f); alpha = Math.min(alpha, 1f); alpha = Math.max(alpha, 0f); return new Color((new java.awt.Color(red, green, blue, alpha)).getRGB()); } static Color interpolateColor(final java.awt.Color COLOR1, final java.awt.Color COLOR2, float fraction); }
@Test public void callInterpolateColorWithGreenBlueColors_returnBeakerColorWithRGB() { Color color = ColorUtils.interpolateColor(java.awt.Color.GREEN, java.awt.Color.BLUE, 0.1f); Assertions.assertThat(color.getRGB()).isNotZero(); } @Test public void callInterpolateColorWithGreenBlueColorsAndFractionIsZero_returnBeakerColorWithGreenValue() { Color color = ColorUtils.interpolateColor(java.awt.Color.GREEN, java.awt.Color.BLUE, 0f); Assertions.assertThat(color).isEqualTo(Color.GREEN); } @Test public void callInterpolateColorWithGreenBlueColorsAndFractionIsOne_returnBeakerColorWithBlueValue() { Color color = ColorUtils.interpolateColor(java.awt.Color.GREEN, java.awt.Color.BLUE, 1f); Assertions.assertThat(color).isEqualTo(Color.BLUE); }
RadioButtons extends SingleSelectionWidget { public RadioButtons() { super(); openComm(); } RadioButtons(); @Override String getModelNameValue(); @Override String getViewNameValue(); static String VIEW_NAME_VALUE; static String MODEL_NAME_VALUE; }
@Test public void shouldSendCommMsgWhenValueChange() throws Exception { RadioButtons widget = radioButtons(); widget.setValue("1"); verifyMsgForProperty(groovyKernel, RadioButtons.VALUE, "1"); } @Test public void shouldSendCommMsgWhenOptionsChange() throws Exception { RadioButtons widget = radioButtons(); widget.setOptions(new String[]{"2", "3"}); verifyMsgForProperty(groovyKernel, RadioButtons.OPTIONS_LABELS, new String[]{"2", "3"}); }
Select extends SingleSelectionWidget { public Select() { super(); openComm(); } Select(); @Override String getModelNameValue(); @Override String getViewNameValue(); static String VIEW_NAME_VALUE; static String MODEL_NAME_VALUE; }
@Test public void shouldSendCommMsgWhenValueChange() throws Exception { Select widget = select(); widget.setValue("1"); verifyMsgForProperty(groovyKernel, Select.VALUE, "1"); } @Test public void shouldSendCommMsgWhenOptionsChange() throws Exception { Select widget = select(); widget.setOptions(new String[]{"2", "3"}); verifyMsgForProperty(groovyKernel, RadioButtons.OPTIONS_LABELS, new String[]{"2", "3"}); }
Dropdown extends SingleSelectionWidget { public Dropdown() { super(); openComm(); } Dropdown(); @Override String getModelNameValue(); @Override String getViewNameValue(); static final String VIEW_NAME_VALUE; static final String MODEL_NAME_VALUE; }
@Test public void shouldSendCommMsgWhenValueChange() throws Exception { Dropdown dropdown = dropdown(); dropdown.setValue("1"); verifyMsgForProperty(groovyKernel, Dropdown.VALUE, "1"); } @Test public void shouldSendCommMsgWhenOptionsChange() throws Exception { Dropdown dropdown = dropdown(); dropdown.setOptions(new String[]{"2", "3"}); verifyMsgForProperty(groovyKernel, Dropdown.OPTIONS_LABELS, new String[]{"2", "3"}); }
SelectMultipleSingle extends SingleSelectionWidget { public SelectMultipleSingle() { super(); openComm(); } SelectMultipleSingle(); @Override String getModelNameValue(); @Override String getViewNameValue(); static String VIEW_NAME_VALUE; static String MODEL_NAME_VALUE; }
@Test public void shouldSendCommMsgWhenValueChange() throws Exception { SelectMultipleSingle widget = selectMultipleSingle(); widget.setOptions(new String[]{"1","2", "3"}); kernel.clearPublishedMessages(); widget.setValue("2"); verifyMsgForProperty(kernel, SelectMultiple.VALUE, "2"); } @Test public void shouldSendCommMsgWhenOptionsChange() throws Exception { SelectMultipleSingle widget = selectMultipleSingle(); widget.setOptions(new String[]{"2", "3"}); verifyMsgForProperty(kernel, SelectMultiple.OPTIONS_LABELS, new String[]{"2", "3"}); }
DatePicker extends ValueWidget<String> { public void setShowTime(final Boolean showTime) { this.showTime = showTime; sendUpdate(SHOW_TIME, showTime); } DatePicker(); @Override void updateValue(Object value); @Override String getValueFromObject(Object input); @Override String getModelNameValue(); @Override String getViewNameValue(); void setShowTime(final Boolean showTime); Boolean getShowTime(); static final String VIEW_NAME_VALUE; static final String MODEL_NAME_VALUE; static final String SHOW_TIME; }
@Test public void shouldSendCommMsgWhenShowTimeChange() throws Exception { DatePicker widget = widget(); widget.setShowTime(true); verifyMsgForProperty(groovyKernel, DatePicker.SHOW_TIME, true); }
ColorPicker extends ValueWidget<String> { public ColorPicker() { super(); openComm(); } ColorPicker(); @Override String getValueFromObject(Object input); Boolean getConcise(); void setConcise(Boolean concise); @Override String getModelNameValue(); @Override String getViewNameValue(); static final String VIEW_NAME_VALUE; static final String MODEL_NAME_VALUE; static final String CONCISE; }
@Test public void shouldSendCommMsgWhenValueChange() throws Exception { ColorPicker widget = colorPicker(); widget.setValue("red"); TestWidgetUtils.verifyMsgForProperty(groovyKernel, ColorPicker.VALUE, "red"); }
Checkbox extends BoolWidget { public Checkbox() { super(); openComm(); } Checkbox(); @Override String getModelNameValue(); @Override String getViewNameValue(); static String VIEW_NAME_VALUE; static String MODEL_NAME_VALUE; }
@Test public void shouldSendCommMsgWhenValueChange() throws Exception { Checkbox widget = checkbox(); widget.setValue(true); verifyMsgForProperty(groovyKernel, Checkbox.VALUE, true); }
ToggleButton extends BoolWidget { public ToggleButton() { super(); openComm(); } ToggleButton(); String getTooltip(); void setTooltip(String tooltip); @Override String getModelNameValue(); @Override String getViewNameValue(); static String VIEW_NAME_VALUE; static String MODEL_NAME_VALUE; static final String TOOLTIP; }
@Test public void shouldSendCommMsgWhenValueChange() throws Exception { ToggleButton widget = toggleButton(); widget.setValue(true); verifyMsgForProperty(groovyKernel, ToggleButton.VALUE, true); }
HTML extends StringWidget { public HTML() { super(); openComm(); } HTML(); @Override String getModelNameValue(); @Override String getViewNameValue(); static final String VIEW_NAME_VALUE; static final String MODEL_NAME_VALUE; }
@Test public void shouldSendCommMsgWhenValueChange() throws Exception { HTML widget = html(); widget.setValue("Hello <b>World</b>"); verifyMsgForProperty(groovyKernel, HTML.VALUE, "Hello <b>World</b>"); }
Label extends StringWidget { public Label() { super(); openComm(); } Label(); @Override String getModelNameValue(); @Override String getViewNameValue(); static final String VIEW_NAME_VALUE; static final String MODEL_NAME_VALUE; }
@Test public void shouldSendCommMsgWhenValueChange() throws Exception { Label widget = label(); widget.setValue("1"); verifyMsgForProperty(groovyKernel, Label.VALUE, "1"); }
Textarea extends StringWidget { public Textarea() { super(); openComm(); } Textarea(); @Override String getModelNameValue(); @Override String getViewNameValue(); static final String VIEW_NAME_VALUE; static final String MODEL_NAME_VALUE; }
@Test public void shouldSendCommMsgWhenValueChange() throws Exception { Textarea widget = textarea(); widget.setValue("Text area 1"); verifyMsgForProperty(groovyKernel, Textarea.VALUE, "Text area 1"); }
Text extends StringWidget { public Text() { super(); openComm(); } Text(); @Override String getModelNameValue(); @Override String getViewNameValue(); static final String VIEW_NAME_VALUE; static final String MODEL_NAME_VALUE; }
@Test public void shouldSendCommMsgWhenValueChange() throws Exception { Text widget = text(); widget.setValue("1"); verifyMsgForProperty(groovyKernel, Text.VALUE, "1"); }