我有一个Java Properties对象,我从内存中String加载,以前从实际.properties文件加载到内存中,如下所示:
this.propertyFilesCache.put(file, FileUtils.fileToString(propFile));
Run Code Online (Sandbox Code Playgroud)
util fileToString实际上从文件中读取文本,其余代码将其存储在HashMap被调用的文件中propertyFilesCache.后来,我从HashMapas中读取文件文本String并将其重新加载到Java Properties对象中,如下所示:
String propFileStr = this.propertyFilesCache.get(fileName);
Properties tempProps = new Properties();
try {
tempProps.load(new ByteArrayInputStream(propFileStr.getBytes()));
} catch (Exception e) {
log.debug(e.getMessage());
}
tempProps.setProperty(prop, propVal);
Run Code Online (Sandbox Code Playgroud)
此时,我已经在我的内存属性文件中替换了我的属性,并且我想从Properties对象中获取文本,就像我正在读取File像上面所做的那样的对象.有没有一种简单的方法可以做到这一点,或者我将不得不迭代属性并String手动创建?
我有一个带有外键引用的模型,看起来像这样
class Plan(models.Model):
template = models.ForeignKey(PlanTemplate)
throttle = models.IntegerField(default=10)
rate_limit = models.BigIntegerField(default=60)
Run Code Online (Sandbox Code Playgroud)
和外键模型:
class PlanTemplate(models.Model):
name = models.CharField(max_length=50)
throttle = models.IntegerField(default=10)
rate_limit = models.BigIntegerField(default=60)
Run Code Online (Sandbox Code Playgroud)
我希望在选择 PlanTemplate 时自动填充计划管理页面上的throttle 和rate_limit。这是 django-admin 可以轻松做到的事情,还是我必须覆盖管理模板并添加一些自定义 JavaScript?
我正在运行 Django 1.2.4。
我正在使用JUnit 4(junit-4.8.2.jar)在我的Java项目上运行测试,并在使用assumeTrue时遇到问题.我有这个基本设置:
public class ClientTest extends TestCase {
@BeforeClass
public void setUp() {
assumeTrue(isPaidAccount());
}
@Test
public void testTheThings() {
// run this test if the user has a paid account
}
}
Run Code Online (Sandbox Code Playgroud)
方法isPaidAccount()返回false,这是预期的,但是忽略了类中的测试,它们都将作为错误返回.这在Eclipse中与JUnit4 Test Runner以及maven一起发生.我也尝试将assumeTrue移动到@Before方法中,如下所示:
public class ClientTest extends TestCase {
@BeforeClass
public void setUp() {
// set up
}
@Before
public void mustHavePaidAccount() {
assumeTrue(isPaidAccount());
}
@Test
public void testTheThings() {
// run this test if the user has a paid account
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我这样做时,它完全忽略了@Before方法,无论如何都只是运行测试.同样,我对Eclipse Test Runner和maven都有相同的行为.我确定我做的事情显然不正确,但我不确定它是什么.