2016-11-16 74 views
1

我使用Citrus靜態響應適配器來模擬服務,並且我需要爲每個測試用例更改其有效負載中的值。理想情況下,我會考慮爲每個測試用例使用字典。還有就是我目前的情況的示例:是否可以應用字典Citrus靜態響應適配器響應模板?

@Autowired 
@Qualifier("checkRegistrationEndpointAdapter") 
public StaticResponseEndpointAdapter checkRegistrationEndpointAdapter; 

protected void setAdapterResponse(StaticResponseEndpointAdapter adapter, String filenamepath){ 
    URL url = this.getClass().getResource(filenamepath); 
    String payload = null; 
    try { 
     payload = Resources.toString(url, Charsets.UTF_8); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    adapter.setMessagePayload(payload); 
} 
@CitrusTest 
public void TestCase02() throws IOException { 

    http() 
      .client(CLIENT) 
      .post() 
      .payload(new ClassPathResource("templates/thisStartRequestMsg.xml", getClass())) 
      .dictionary("TC02"); 

    http() 
      .client(CLIENT) 
      .response() 
      .messageType("xml") 
      .payload(new ClassPathResource("templates/thisStartResponseMsg.xml", getClass())); 

    action(new AbstractTestAction() { 
     @Override 
     public void doExecute(TestContext testContext) { 
      setAdapterResponse(checkRegistrationEndpointAdapter, "templates/check-registration-v1CheckRegistrationResponseMsg.xml"); 
     } 
    }); 

    http() 
      .client(CLIENT) 
      .response() 
      .messageType("xml") 
      .payload(new ClassPathResource("templates/check-registration-v1CheckRegistrationRequestMsg.xml", getClass())) 
      .dictionary("TC02"); 
} 

如何我可以申請詞典在我setAdapterResponse方法設定的負載? 注意:此問題涉及Can I use Citrus variable in Citrus static response adapter payload?

回答

0

靜態響應適配器目前不支持數據字典。我想知道爲什麼你爲靜態響應適配器付出瞭如此多的努力?爲什麼不使用完整的Citrus http服務器功能來接收請求並在測試用例中提供響應?

+0

感謝您的回答。我嘗試使用靜態響應適配器,因爲那時候我還沒有回答https://github.com/christophd/citrus-samples/issues/10。 –