/*
* Copyright 2015 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.inferred.freebuilder.client.rpc;
import com.google.gwt.core.client.GWT;
import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
public class MapTest extends GWTTestCase {
private static final int RPC_TIMEOUT = 15000;
private static final String MODULE_NAME = "org.inferred.freebuilder.TestServer";
private static final MapGwtType VALUE = new MapGwtType.Builder()
.putDistances("small", 1.0)
.putDistances("medium", 10.3)
.putDistances("large", 112.5)
.build();
private MapTestServiceAsync customFieldSerializerTestService;
@Override
public String getModuleName() {
return MODULE_NAME;
}
@Override
protected void gwtSetUp() throws Exception {
super.gwtSetUp();
delayTestFinish(RPC_TIMEOUT);
}
public void testSerialization() {
MapTestServiceAsync service = getServiceAsync();
service.echo(VALUE, new AsyncCallback<MapGwtType>() {
@Override
public void onFailure(Throwable caught) {
throw new AssertionError(caught);
}
@Override
public void onSuccess(MapGwtType result) {
assertEquals(VALUE, result);
finishTest();
}
});
}
private MapTestServiceAsync getServiceAsync() {
if (customFieldSerializerTestService == null) {
customFieldSerializerTestService =
(MapTestServiceAsync) GWT.create(MapTestService.class);
((ServiceDefTarget) customFieldSerializerTestService)
.setServiceEntryPoint(GWT.getModuleBaseURL() + "map");
}
return customFieldSerializerTestService;
}
}