|
| 1 | +package org.tron.core.services.interfaceOnPBFT.http; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertTrue; |
| 4 | +import static org.junit.Assert.fail; |
| 5 | +import static org.tron.common.utils.client.utils.HttpMethed.createRequest; |
| 6 | + |
| 7 | +import com.alibaba.fastjson.JSONObject; |
| 8 | +import java.io.IOException; |
| 9 | +import java.io.UnsupportedEncodingException; |
| 10 | +import javax.annotation.Resource; |
| 11 | +import org.apache.http.client.methods.HttpGet; |
| 12 | +import org.apache.http.client.methods.HttpPost; |
| 13 | +import org.junit.BeforeClass; |
| 14 | +import org.junit.ClassRule; |
| 15 | +import org.junit.Test; |
| 16 | +import org.junit.rules.TemporaryFolder; |
| 17 | +import org.springframework.mock.web.MockHttpServletRequest; |
| 18 | +import org.springframework.mock.web.MockHttpServletResponse; |
| 19 | +import org.tron.common.BaseTest; |
| 20 | +import org.tron.core.Constant; |
| 21 | +import org.tron.core.config.args.Args; |
| 22 | + |
| 23 | +public class GetBandwidthPricesOnPBFTServletTest extends BaseTest { |
| 24 | + |
| 25 | + @ClassRule |
| 26 | + public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); |
| 27 | + @Resource |
| 28 | + private GetBandwidthPricesOnPBFTServlet getBandwidthPricesOnPBFTServlet; |
| 29 | + |
| 30 | + @BeforeClass |
| 31 | + public static void init() throws IOException { |
| 32 | + Args.setParam(new String[]{"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void testGet() { |
| 37 | + MockHttpServletRequest request = createRequest(HttpGet.METHOD_NAME); |
| 38 | + MockHttpServletResponse response = new MockHttpServletResponse(); |
| 39 | + getBandwidthPricesOnPBFTServlet.doPost(request, response); |
| 40 | + try { |
| 41 | + String contentAsString = response.getContentAsString(); |
| 42 | + JSONObject result = JSONObject.parseObject(contentAsString); |
| 43 | + assertTrue(result.containsKey("prices")); |
| 44 | + } catch (UnsupportedEncodingException e) { |
| 45 | + fail(e.getMessage()); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void testPost() { |
| 51 | + MockHttpServletRequest request = createRequest(HttpPost.METHOD_NAME); |
| 52 | + try { |
| 53 | + MockHttpServletResponse response = new MockHttpServletResponse(); |
| 54 | + getBandwidthPricesOnPBFTServlet.doPost(request, response); |
| 55 | + String contentAsString = response.getContentAsString(); |
| 56 | + JSONObject result = JSONObject.parseObject(contentAsString); |
| 57 | + assertTrue(result.containsKey("prices")); |
| 58 | + } catch (UnsupportedEncodingException e) { |
| 59 | + fail(e.getMessage()); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments