Skip to content

Commit

Permalink
Issue robotframework#65: Fix get_library_information when called mult…
Browse files Browse the repository at this point in the history
…iple times

Also extends tests to cover this behaviour.
  • Loading branch information
lasselindqvist committed May 20, 2022
1 parent 82f904d commit e993ba0
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public ServerMethods(RemoteServerServlet servlet) {
log = LogFactory.getLog(ServerMethods.class);
this.servlet = servlet;
}

private static final String STOP_REMOTE_SERVER = "stop_remote_server";

/**
* Get an array containing the names of the keywords that the library
Expand All @@ -54,7 +56,9 @@ public List<String> get_keyword_names() {
List<String> names = servlet.getLibrary().getKeywordNames();
if (names == null || names.size() == 0)
throw new RuntimeException("No keywords found in the test library");
names.add("stop_remote_server");
if (!names.contains(STOP_REMOTE_SERVER)) {
names.add(STOP_REMOTE_SERVER);
}
return names;
} catch (Throwable e) {
log.warn("", e);
Expand Down
26 changes: 18 additions & 8 deletions src/test/java/org/robotframework/examplelib/FullDynamic.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package org.robotframework.examplelib;

import org.robotframework.javalib.library.AnnotationLibrary;
import org.robotframework.javalib.library.RobotFrameworkDynamicAPI;

import java.util.List;
import java.util.Map;

public class FullDynamic {
public class FullDynamic implements RobotFrameworkDynamicAPI
{
private final AnnotationLibrary lib;

public FullDynamic() {
lib = new AnnotationLibrary();
lib.addKeywordPattern("org/robotframework/examplelib/impl/**.class");
Expand All @@ -18,14 +23,16 @@ public List<String> getKeywordNames() {
* AnnotationLibrary re-throws all exceptions as RuntimeExceptions. Unwrap
* it to obtain the original exception.
*/
public Object runKeyword(String keywordName, List<String> args) throws Throwable {
try {
return lib.runKeyword(keywordName, args, null);
} catch (RuntimeException e) {
throw e.getCause();
}
@Override
public Object runKeyword(String keywordName, List args) {
return lib.runKeyword(keywordName, args, null);
}

@Override
public Object runKeyword(String keywordName, List args, Map kwargs) {
return lib.runKeyword(keywordName, args, kwargs);
}

public List<String> getKeywordArguments(String keywordName) {
return lib.getKeywordArguments(keywordName);
}
Expand All @@ -37,6 +44,9 @@ public String getKeywordDocumentation(String keywordName) {
return lib.getKeywordDocumentation(keywordName);
}

private AnnotationLibrary lib;

public AnnotationLibrary getLib() {
return lib;
}

}
26 changes: 26 additions & 0 deletions src/test/java/org/robotframework/examplelib/FullDynamicTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.robotframework.examplelib;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;

import org.robotframework.remoteserver.servlet.ServerMethods;
import org.testng.Assert;
import org.testng.annotations.Test;
public class FullDynamicTest {


@Test
public void testCallingTwice() throws IOException, ServletException {
FullDynamic dynamic = new FullDynamic();
SimpleRemoteServerServlet servlet = new SimpleRemoteServerServlet(dynamic.getLib());
ServerMethods methods = new ServerMethods(servlet);

Map<String, Object> map1 = methods.get_library_information();
Map<String, Object> map2 = methods.get_library_information();
// The exact count we don't care about.
// We just want the information to stay consistent.
Assert.assertEquals(map1.size(), map2.size());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.robotframework.examplelib;

import org.robotframework.javalib.library.AnnotationLibrary;
import org.robotframework.remoteserver.library.RemoteLibrary;
import org.robotframework.remoteserver.library.RemoteLibraryFactory;
import org.robotframework.remoteserver.servlet.RemoteServerServlet;

public class SimpleRemoteServerServlet extends RemoteServerServlet {

private static final long serialVersionUID = -2729050484180284488L;
private final RemoteLibrary library;

public SimpleRemoteServerServlet(AnnotationLibrary library) {
RemoteLibraryFactory libraryFactory = createLibraryFactory();
RemoteLibrary remoteLibrary = libraryFactory.createRemoteLibrary(library);
this.library = remoteLibrary;
}

public RemoteLibrary getLibrary() {
return this.library;
}
}

0 comments on commit e993ba0

Please sign in to comment.