{"action":"closed","issue":{"url":"https://api.github.com/repos/nginx-clojure/nginx-clojure/issues/101","labels_url":"https://api.github.com/repos/nginx-clojure/nginx-clojure/issues/101/labels{/name}","comments_url":"https://api.github.com/repos/nginx-clojure/nginx-clojure/issues/101/comments","events_url":"https://api.github.com/repos/nginx-clojure/nginx-clojure/issues/101/events","html_url":"https://github.com/nginx-clojure/nginx-clojure/issues/101","id":112373630,"number":101,"title":"After mock tests request.get() always returns null when run junit tests with an embedded nginx-clojure ","user":{"login":"xfeep","id":6120241,"avatar_url":"https://avatars.githubusercontent.com/u/6120241?v=3","gravatar_id":"","url":"https://api.github.com/users/xfeep","html_url":"https://github.com/xfeep","followers_url":"https://api.github.com/users/xfeep/followers","following_url":"https://api.github.com/users/xfeep/following{/other_user}","gists_url":"https://api.github.com/users/xfeep/gists{/gist_id}","starred_url":"https://api.github.com/users/xfeep/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xfeep/subscriptions","organizations_url":"https://api.github.com/users/xfeep/orgs","repos_url":"https://api.github.com/users/xfeep/repos","events_url":"https://api.github.com/users/xfeep/events{/privacy}","received_events_url":"https://api.github.com/users/xfeep/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nginx-clojure/nginx-clojure/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/nginx-clojure/nginx-clojure/labels/nginx-clojure-embed","name":"nginx-clojure-embed","color":"207de5"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/nginx-clojure/nginx-clojure/milestones/13","html_url":"https://github.com/nginx-clojure/nginx-clojure/milestones/0.4.3","labels_url":"https://api.github.com/repos/nginx-clojure/nginx-clojure/milestones/13/labels","id":1299325,"number":13,"title":"0.4.3","description":"","creator":{"login":"xfeep","id":6120241,"avatar_url":"https://avatars.githubusercontent.com/u/6120241?v=3","gravatar_id":"","url":"https://api.github.com/users/xfeep","html_url":"https://github.com/xfeep","followers_url":"https://api.github.com/users/xfeep/followers","following_url":"https://api.github.com/users/xfeep/following{/other_user}","gists_url":"https://api.github.com/users/xfeep/gists{/gist_id}","starred_url":"https://api.github.com/users/xfeep/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xfeep/subscriptions","organizations_url":"https://api.github.com/users/xfeep/orgs","repos_url":"https://api.github.com/users/xfeep/repos","events_url":"https://api.github.com/users/xfeep/events{/privacy}","received_events_url":"https://api.github.com/users/xfeep/received_events","type":"User","site_admin":false},"open_issues":5,"closed_issues":1,"state":"open","created_at":"2015-09-10T12:54:57Z","updated_at":"2015-10-25T16:54:49Z","due_on":null,"closed_at":null},"comments":0,"created_at":"2015-10-20T13:52:22Z","updated_at":"2015-10-25T16:54:49Z","closed_at":"2015-10-25T16:54:49Z","body":"The original report of this issue is from [nginx-clojure google group](https://groups.google.com/forum/#!topic/nginx-clojure/rHR5wjmY2YU) .\r\nWhen we run both mock tests with mocked NginxJavaRequest and junit tests with an embedded nginx-clojure request.get() will always return null if we run junit tests with an embedded nginx-clojure after mock tests with mocked NginxJavaRequest. e.g.\r\n\r\n\r\nTestByMock.java\r\n----------------\r\n```java\r\nimport static org.junit.Assert.assertEquals;\r\nimport static org.mockito.Mockito.when;\r\n\r\nimport java.io.IOException;\r\nimport java.util.Map;\r\n\r\nimport org.junit.After;\r\nimport org.junit.Before;\r\nimport org.junit.Test;\r\nimport org.mockito.Mock;\r\nimport org.mockito.MockitoAnnotations;\r\n\r\nimport nginx.clojure.MiniConstants;\r\nimport nginx.clojure.embed.NginxEmbedServer;\r\nimport nginx.clojure.java.ArrayMap;\r\nimport nginx.clojure.java.NginxJavaRequest;\r\n\r\npublic class TestByMock {\r\n\r\n\tstatic {\r\n\t\tMap<String, String> opts = ArrayMap.create(\"port\", \"0\", \r\n\t\t\t\t\"http-user-defined\", \"handlers_lazy_init on;\");\r\n\t\tNginxEmbedServer.getServer().start(\"empty-handler\", opts);\r\n\t\tNginxEmbedServer.getServer().stop();\r\n\t}\r\n\t\r\n\t@Mock\r\n\tprivate NginxJavaRequest nginxJavaRequest;\r\n\t\r\n\t@Before\r\n\tpublic void setUp() throws Exception {\r\n\t\tMockitoAnnotations.initMocks( this );\r\n\t    when(nginxJavaRequest.get(MiniConstants.SCHEME)).thenReturn(\"http\");\r\n\t    when(nginxJavaRequest.get(MiniConstants.SERVER_PORT)).thenReturn(\"8082\");\r\n\t    when(nginxJavaRequest.get(MiniConstants.URI)).thenReturn(\"/test.jsp\");\r\n\t}\r\n\r\n\t@After\r\n\tpublic void tearDown() throws Exception {\r\n\t}\r\n\r\n\t@Test\r\n\tpublic void testHandler() throws IOException {\r\n\t\tObject[] resp = new HelloURIHandler().invoke(nginxJavaRequest);\r\n\t\tassertEquals(3, resp.length);\r\n\t\tassertEquals(200, resp[0]);\r\n\t\tassertEquals(\"Hello, /test.jsp, 8082\", resp[2]);\r\n\t}\r\n\r\n}\r\n```\r\n\r\nTestByMock.java\r\n----------------\r\n\r\n```java\r\nimport java.util.Map;\r\nimport static org.junit.Assert.assertEquals;\r\nimport org.apache.http.client.methods.CloseableHttpResponse;\r\nimport org.apache.http.client.methods.HttpGet;\r\nimport org.apache.http.impl.client.CloseableHttpClient;\r\nimport org.apache.http.impl.client.HttpClients;\r\nimport org.apache.http.util.EntityUtils;\r\nimport org.junit.After;\r\nimport org.junit.Before;\r\nimport org.junit.Test;\r\n\r\nimport nginx.clojure.embed.NginxEmbedServer;\r\nimport nginx.clojure.java.ArrayMap;\r\n\r\npublic class TestByEmbed {\r\n\r\n\t@Before\r\n\tpublic void setUp() throws Exception {\r\n\t\tMap<String, String> opts = ArrayMap.create(\"port\", \"8082\");\r\n\t\tNginxEmbedServer.getServer().start(HelloURIHandler.class.getName(), opts);\r\n\t}\r\n\r\n\t@After\r\n\tpublic void tearDown() throws Exception {\r\n\t\tNginxEmbedServer.getServer().stop();\r\n\t}\r\n\r\n\t@Test\r\n\tpublic void testRemote() throws Exception {\r\n\t\tCloseableHttpClient httpclient = HttpClients.createDefault();\r\n\t    HttpGet httpget = new HttpGet(\"http://127.0.0.1:8082/test.jsp\");\r\n\t    try (CloseableHttpResponse httpResponse = httpclient.execute(httpget)) {\r\n\t    \tassertEquals(\"Hello, /test.jsp, 8082\", EntityUtils.toString(httpResponse.getEntity()));\r\n\t    }\r\n\t}\r\n\r\n}\r\n\r\n```\r\n\r\nResult of running both of them\r\n----------------\r\n```\r\norg.junit.ComparisonFailure: expected:<Hello, [/test.jsp, 8082]> but was:<Hello, [null, null]>\r\n\tat org.junit.Assert.assertEquals(Assert.java:115)\r\n\tat org.junit.Assert.assertEquals(Assert.java:144)\r\n\tat nginx.clojure.mock.TestByEmbed.testRemote(TestByEmbed.java:35)\r\n```\r\n\r\nIt can be resolved by start + stop  NginxEmbedServer before running tests. e.g.\r\n\r\n```java\r\npublic class TestByMock {\r\n\r\n\tstatic {\r\n                // for v0.4.2 \r\n\t\tMap<String, String> opts = ArrayMap.create(\"port\", \"0\", \r\n\t\t\t\t\"http-user-defined\", \"handlers_lazy_init on;\");\r\n                // for v0.4.1 \r\n                // Map<String, String> opts = ArrayMap.create(\"port\", no-zero-port, \r\n\t\t//\t\t\"http-user-defined\", \"handlers_lazy_init on;\");\r\n\t\tNginxEmbedServer.getServer().start(\"empty-handler\", opts);\r\n\t\tNginxEmbedServer.getServer().stop();\r\n                NginxJavaHandlerFactory.fetchFactory(\"java\");\r\n                //uncomment next line when use clojure\r\n                //NginxJavaHandlerFactory.fetchFactory(\"clojure\");\r\n\t}\r\n```\r\n\r\nIt will be fixed in release v0.4.3 .\r\n\r\n"}}