我一直在努力解决这个问题已经有一段时间了,并且无法找到解决方案.我需要用户能够通过一次登录查看多个顶级域名.
我的理解是,这需要设置environment.rb和调用before_dispatch.这就是我想出来的:
require 'activesupport'
require 'dispatcher'
module ActionController
class Dispatcher
def set_session_domain
ActionController::Base.session_options.update :session_domain => "#{@request.host}"
end
before_dispatch :set_session_domain
end
end
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试从中提取值时,这似乎不起作用session[:session_domain].
任何帮助是极大的赞赏.
所以,我之前并没有真正参与编写单元测试的实践 - 现在我很喜欢,我需要检查一下我是否在正确的轨道上.
假设你有一个处理数学计算的课程.
class Vector3
{
public: // Yes, public.
float x,y,z ;
// ... ctors ...
} ;
Vector3 operator+( const Vector3& a, const Vector3 &b )
{
return Vector3( a.x + b.y /* oops!! hence the need for unit testing.. */,
a.y + b.y,
a.z + b.z ) ;
}
Run Code Online (Sandbox Code Playgroud)
我有两种方法可以真正想到在Vector类上进行单元测试:
bool UnitTest_ClassVector3_operatorPlus()
{
Vector3 a( 2, 3, 4 ) ;
Vector3 b( 5, 6, 7 ) ;
Vector3 result = a + b ;
// …Run Code Online (Sandbox Code Playgroud) 我有一个C语言的项目,老师命令做一个项目的Gui.我只能使用C或C++作为GUI部分.
任何人都可以建议我一些简单的开源图形库教程,因为这将是我的第一个GUI.
谢谢
我正在尝试集成Spring Security和GWT.我也在使用gwt-incubator-security.我按照wiki页面上的描述配置了所有内容.我设法通过使用intercept-url来获得安全性,但我无法使用注释使其工作.关于问题是什么的任何想法?
PS我使用的是Spring 2.5.6,Spring Security 2.0.5和gwt-incubator-security 1.0.1.欢迎任何有用的链接和评论.
这是我的配置文件
applicationContext.xml中
<?xml version="1.0" encoding="UTF-8"?>
<global-method-security secured-annotations="enabled"
jsr250-annotations="disabled" />
<http auto-config="true">
<!-- <intercept-url pattern="/**/*.rpc" access="ROLE_USER" /> -->
<intercept-url pattern="/gwt/**" access="ROLE_USER" />
<intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
</http>
<authentication-provider>
<user-service>
<user name="rod" password="koala"
authorities="ROLE_SUPERVISOR, ROLE_USER, ROLE_TELLER" />
<user name="dianne" password="emu" authorities="ROLE_USER,ROLE_TELLER" />
<user name="scott" password="wombat" authorities="ROLE_USER" />
<user name="peter" password="opal" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
<beans:bean id="greetService" class="com.ct.test.server.GreetingServiceImpl" />
Run Code Online (Sandbox Code Playgroud)
web.xml中
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>Spring_test.html</welcome-file>
</welcome-file-list>
<!-- Spring related …Run Code Online (Sandbox Code Playgroud) 我想对使用Apache CXF编写的RESTful接口进行单元测试.
我使用ServletContext来加载一些资源,所以我有:
@Context
private ServletContext servletContext;
Run Code Online (Sandbox Code Playgroud)
如果我在Glassfish上部署它,则会注入ServletContext并且它会按预期工作.但我不知道如何在我的服务类中注入ServletContext,以便我可以使用JUnit测试来测试它.
我使用Spring 3.0,JUnit 4,CXF 2.2.3和Maven.
我正在编写一个实用程序(恰好在python中),它以TCL脚本的形式生成输出.给定python中的一些任意字符串变量(不是unicode),我想生成一个类似的TCL行
set s something
Run Code Online (Sandbox Code Playgroud)
...将TCL变量' s'设置为该精确字符串,无论其中包含什么奇怪的字符.没有变得太奇怪,我不想让输出比需要的更麻烦.我相信一个体面的方法
如果字符串不是空的并且只包含字母数字,而某些字符.-_(但绝对不是$"{}\)那么它可以原样使用;
如果它只包含可打印字符而没有双引号或花括号(并且不以反斜杠结尾),那么只需将{}它放在一边;
否则,""在使用\转义后放置它" { } \ $ [ ] ,并\nnn转义为非打印字符.
问题:是否需要在双引号内转义的完整字符集?我在文档中找不到这个.我是否错过了一些东西(我几乎错过了(2)的字符串不能以\结尾).
我知道还有许多其他字符串可以引用 {},但似乎很难轻易识别它们.此外,看起来非打印字符(特别是换行符)可以使用(2)如果您不介意它们确实存在于TCL输出中.
我正在使用Apache CXF版本2.4.0.我正在尝试创建一个Restful服务.
以下示例适用于2.3.4,但在2.4.0中不起作用.我应该在beans配置文件中做些什么?
当我在我的bean配置文件中包含下面的xml行时.
<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
Run Code Online (Sandbox Code Playgroud)
我收到以下stacktrace错误:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:配置问题:无法从URL位置导入bean定义[classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml]
违规资源:ServletContext资源[/WEB-INF/beans.xml]; 嵌套异常是org.springframework.beans.factory.BeanDefinitionStoreException:
IOException从类路径资源解析XML文档[META-INF/cxf/cxf-extension-jaxrs-binding.xml]; 嵌套异常是java.io.FileNotFoundException:无法打开类路径资源[META-INF/cxf/cxf-extension-jaxrs-binding.xml],因为它在org.springframework.beans.factory.parsing.FailFastProblemReporter中不存在.错误(FailFastProblemReporter.java:68)
我的POM依赖关系如下.这适用于2.3.4但不适用于2.4.0.有什么建议?该xml扩展行是否已弃用或包含在另一个jar中?
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle-jaxrs</artifactId>
<version>2.3.4</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
</exclusion>
</exclusions>
</dependency>
Run Code Online (Sandbox Code Playgroud) 我想修改一个传出的SOAP请求.我想从信封的主体中删除2个xml节点.我设法建立一个Interceptor并将生成的消息集的String值获取到端点.
但是,以下代码似乎不起作用,因为未按预期编辑传出消息.有没有人有关于如何做到这一点的一些代码或想法?
public class MyOutInterceptor extends AbstractSoapInterceptor {
public MyOutInterceptor() {
super(Phase.SEND);
}
public void handleMessage(SoapMessage message) throws Fault {
// Get message content for dirty editing...
StringWriter writer = new StringWriter();
CachedOutputStream cos = (CachedOutputStream)message.getContent(OutputStream.class);
InputStream inputStream = cos.getInputStream();
IOUtils.copy(inputStream, writer, "UTF-8");
String content = writer.toString();
// remove the substrings from envelope...
content = content.replace("<idJustification>0</idJustification>", "");
content = content.replace("<indicRdv>false</indicRdv>", "");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
outputStream.write(content.getBytes(Charset.forName("UTF-8")));
message.setContent(OutputStream.class, outputStream);
}
Run Code Online (Sandbox Code Playgroud) 我有一个带JAXB注释的员工类:
@XmlRootElement(name = "employee")
public class Employee {
private Integer id;
private String name;
...
@XmlElement(name = "id")
public int getId() {
return this.id;
}
... // setters and getters for name, equals, hashCode, toString
}
Run Code Online (Sandbox Code Playgroud)
还有一个JAX-RS资源对象(我使用的是Jersey 1.12)
@GET
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Path("/")
public List<Employee> findEmployees(
@QueryParam("name") String name,
@QueryParam("page") String pageNumber,
@QueryParam("pageSize") String pageSize) {
...
List<Employee> employees = employeeService.findEmployees(...);
return employees;
}
Run Code Online (Sandbox Code Playgroud)
此端点工作正常.我明白了
<employees>
<employee>
<id>2</id>
<name>Ana</name>
</employee>
</employees>
Run Code Online (Sandbox Code Playgroud)
但是,如果我更改方法以返回Response对象,并将员工列表放在响应正文中,如下所示:
@GET
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) …Run Code Online (Sandbox Code Playgroud) 有没有办法使用JaCoCo和tomcat7-maven-plugin嵌入式实例获取代码覆盖?
jacoco-maven-plugin在我的WAR POM中配置来检测我的单元测试,但我不确定如何将jacoco代理连接到嵌入式Tomcat实例来检测针对Tomcat运行的集成测试.鉴于嵌入了Tomcat实例,我不确定这种方法是否可行.有没有其他方法可以实现这一目标?我可以从使用Tomcat Maven插件切换到使用Cargo获取覆盖范围,但如果可能的话,我宁愿坚持使用Tomcat插件.
以下是我POM的一些相关摘要:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.2.201302030002</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.14</version>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<systemProperties>
<!-- as expected, this system property doesn't work since Tomcat is embedded, but this is the type of config I'm looking for -->
<JAVA_OPTS>-javaagent:${project.build.directory}/${jacoco.jar}=destfile=${project.build.directory}/jacoco.exec,append=true</JAVA_OPTS>
</systemProperties>
</configuration>
<executions>
<execution>
<id>tomcat-startup</id>
<goals>
<goal>run-war-only</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<fork>true</fork>
</configuration>
</execution>
<execution>
<id>tomcat-shutdown</id>
<goals> …Run Code Online (Sandbox Code Playgroud)