Commit 163f6789 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

issue #43 - sending names to javascript with ' character aws crashing

connection
parent f1a88219
......@@ -526,5 +526,4 @@ public class ExporterServiceTest extends ServiceTestFunctions {
throw e;
}
}
}
......@@ -109,12 +109,16 @@ public abstract class AbstractMarkerManagerBean<T extends ISearchResultView> ext
if ("".equals(overlayCollection)) {
logger.warn(this.getClass().getSimpleName() + ": Cannot refresh data in JavaScript, because overlayCollection is not set");
} else {
String json = "null";
Gson gsonParser = new Gson();
String dataEncoded = "null";
if (dataToSend != null) {
json = new Gson().toJson(dataToSend);
dataEncoded = gsonParser.toJson(dataToSend);
}
String javascriptCode = "ServerConnector.updateOverviewElementDetailData('" + overlayCollection + "','" + searchResultIdentifier + "',"
+ new Gson().toJson(ei) + ", " + json + ");\n";
String nameEncoded = gsonParser.toJson(overlayCollection);
String resultResultIdEncoded = gsonParser.toJson(searchResultIdentifier);
String elementIdEncoded = gsonParser.toJson(ei);
String javascriptCode = "ServerConnector.updateOverviewElementDetailData(" + nameEncoded + "," + resultResultIdEncoded + "," + elementIdEncoded + ", "
+ dataEncoded + ");\n";
executeJavascript(javascriptCode.toString());
}
}
......
package lcsb.mapviewer.bean;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.events.Event;
import lcsb.mapviewer.events.Listener;
import org.apache.commons.lang3.mutable.MutableInt;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class AbstractManagedBeanTest {
class AbstractManagedBeanMock extends AbstractManagedBean {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public void clear() {
}
public void callMockEvent(String data) {
callListeners(new EventMock(data));
}
@Override
public void init() {
// TODO Auto-generated method stub
}
};
class EventMock extends Event {
String data = "";
public EventMock(String d) {
data = d;
}
}
AbstractManagedBeanMock mockBean;
@Before
public void setUp() throws Exception {
mockBean = new AbstractManagedBeanMock();
}
@After
public void tearDown() throws Exception {
}
@Test
public void testListeners() throws Exception {
final MutableInt called = new MutableInt(0);
try {
Listener<EventMock> listener = new Listener<EventMock>(EventMock.class) {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
protected void handle(EventMock event) {
called.add(1);
}
};
mockBean.registerListener(listener);
assertEquals(new MutableInt(0), called);
mockBean.callMockEvent("hi");
assertEquals(new MutableInt(1), called);
mockBean.callMockEvent("hi2");
assertEquals(new MutableInt(2), called);
mockBean.unregisterListener(listener);
mockBean.callMockEvent("hi3");
assertEquals(new MutableInt(2), called);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testRemoveListeners() throws Exception {
final MutableInt called = new MutableInt(0);
try {
Listener<EventMock> listener = new Listener<EventMock>(EventMock.class) {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
protected void handle(EventMock event) {
called.add(1);
}
};
try {
mockBean.unregisterListener(listener);
fail("Exception expected");
} catch (InvalidArgumentException e) {
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
package lcsb.mapviewer.bean;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.apache.commons.lang3.mutable.MutableInt;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.events.Event;
import lcsb.mapviewer.events.Listener;
public class AbstractManagedBeanTest {
Logger logger = Logger.getLogger(AbstractManagedBeanTest.class);
class AbstractManagedBeanMock extends AbstractManagedBean {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public void clear() {
}
public void callMockEvent(String data) {
callListeners(new EventMock(data));
}
@Override
public void init() {
// TODO Auto-generated method stub
}
};
class EventMock extends Event {
String data = "";
public EventMock(String d) {
data = d;
}
}
AbstractManagedBeanMock mockBean;
@Before
public void setUp() throws Exception {
mockBean = new AbstractManagedBeanMock();
}
@After
public void tearDown() throws Exception {
}
@Test
public void testListeners() throws Exception {
final MutableInt called = new MutableInt(0);
try {
Listener<EventMock> listener = new Listener<EventMock>(EventMock.class) {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
protected void handle(EventMock event) {
called.add(1);
}
};
mockBean.registerListener(listener);
assertEquals(new MutableInt(0), called);
mockBean.callMockEvent("hi");
assertEquals(new MutableInt(1), called);
mockBean.callMockEvent("hi2");
assertEquals(new MutableInt(2), called);
mockBean.unregisterListener(listener);
mockBean.callMockEvent("hi3");
assertEquals(new MutableInt(2), called);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testRemoveListeners() throws Exception {
final MutableInt called = new MutableInt(0);
try {
Listener<EventMock> listener = new Listener<EventMock>(EventMock.class) {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
protected void handle(EventMock event) {
called.add(1);
}
};
try {
mockBean.unregisterListener(listener);
fail("Exception expected");
} catch (InvalidArgumentException e) {
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment